Gearman 工作状态问题

发布于 2024-11-01 21:23:15 字数 212 浏览 0 评论 0原文

我有一台 Gearman 服务器正在运行一个需要几分钟才能完成的进程。我正在运行一个进度条来显示完成情况,并尝试使用 Gearman PHP 扩展和 jobStatus() 函数获取进度条的百分比。

该作业肯定处于活动状态并已找到,因为前两个字段(已知 + 仍在运行)返回 true。然而,第三个和第四个字段(完成百分比的分子和分母)什么也没返回。有谁知道为什么会这样或者这些数字是如何计算的?

I have a Gearman server running a process which takes a few minutes to finish. I'm running a progress bar to show completion, and am attempting to get the percentages for the bar using the Gearman PHP extension and the jobStatus() function.

The job is definitely active and found, as the first two fields (known + still running) return to true. However the third and fourth fields (numerator and denominator of completion percentage) return with nothing. Does anyone know why this might be or how these numbers are computed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞清仓 2024-11-08 21:23:15
public bool GearmanJob::sendStatus ( int $numerator , int $denominator )

向作业发送状态信息
服务器和任何侦听客户端。使用
这指定了多少百分比
工作已经完成。

为了能够使用它,您可能还需要对客户端进行一些更改来处理通信。

示例

client.php

<?php
global $argc,$argv;

if (!file_exists($argv[1])) {
        echo "File not found\n";
        exit(1);
}

$gmclient= new GearmanClient();
$gmclient->addServer();
do
{
  $result = $gmclient->do("linecount", file_get_contents($argv[1]));
  # Check for various return packets and errors.

  switch($gmclient->returnCode())
  {
    case GEARMAN_WORK_STATUS:
      list($numerator, $denominator)= $gmclient->doStatus();
      echo "Status: " . sprintf("%d%%",($numerator/$denominator)*100)
             . " complete\r";
      break;
    case GEARMAN_SUCCESS:
      break;
  }
}
while($gmclient->returnCode() != GEARMAN_SUCCESS);

echo "\nResult: $result\n";

worker.php

<?php
$worker= new GearmanWorker();
$worker->addServer();
$worker->addFunction("linecount", "linecount");
while ($worker->work());

    function linecount($job)
    {
            $lines = preg_split('/[\r\n]/',
                       $job->workload(),null,PREG_SPLIT_NO_EMPTY);
            $linecount = count($lines);
            $n = 0;
            foreach ($lines as $line) {
                    usleep(3000);
                    $n++;
                    $job->sendStatus($n,$linecount);
                    $ret++;
            }
            return $ret;
    }
public bool GearmanJob::sendStatus ( int $numerator , int $denominator )

Sends status information to the job
server and any listening clients. Use
this to specify what percentage of the
job has been completed.

To be able to use it, you will probably also have alter the client a bit to handle the communication.

Example

client.php

<?php
global $argc,$argv;

if (!file_exists($argv[1])) {
        echo "File not found\n";
        exit(1);
}

$gmclient= new GearmanClient();
$gmclient->addServer();
do
{
  $result = $gmclient->do("linecount", file_get_contents($argv[1]));
  # Check for various return packets and errors.

  switch($gmclient->returnCode())
  {
    case GEARMAN_WORK_STATUS:
      list($numerator, $denominator)= $gmclient->doStatus();
      echo "Status: " . sprintf("%d%%",($numerator/$denominator)*100)
             . " complete\r";
      break;
    case GEARMAN_SUCCESS:
      break;
  }
}
while($gmclient->returnCode() != GEARMAN_SUCCESS);

echo "\nResult: $result\n";

worker.php

<?php
$worker= new GearmanWorker();
$worker->addServer();
$worker->addFunction("linecount", "linecount");
while ($worker->work());

    function linecount($job)
    {
            $lines = preg_split('/[\r\n]/',
                       $job->workload(),null,PREG_SPLIT_NO_EMPTY);
            $linecount = count($lines);
            $n = 0;
            foreach ($lines as $line) {
                    usleep(3000);
                    $n++;
                    $job->sendStatus($n,$linecount);
                    $ret++;
            }
            return $ret;
    }
む无字情书 2024-11-08 21:23:15

工作人员是否配置为返回状态?

如果您自己编写它们,则必须做一些额外的工作才能让它们返回详细信息。

Is the worker configured to return status?

If you write them yourself you have to do a bit of extra work to get them to return details as they go though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文