Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class Worker extends \Illuminate\Queue\Worker implements

protected $extensions = [];

protected $processed = 0;

protected $startTime = 0;

public function daemon($connectionName, $queueNames, WorkerOptions $options)
{
$this->connectionName = $connectionName;
Expand All @@ -56,13 +60,15 @@ public function daemon($connectionName, $queueNames, WorkerOptions $options)
parent::daemon($connectionName, $this->queueNames, $options);
return;
}
$this->startTime = hrtime(true);

$context = $this->queue->getQueueInteropContext();
$queueConsumer = new QueueConsumer($context, new ChainExtension(
$this->getAllExtensions([$this])
));
foreach (explode(',', $queueNames) as $queueName) {
$queueConsumer->bindCallback($queueName, function() {
$this->processed++;
$this->runJob($this->job, $this->connectionName, $this->options);

return Result::ALREADY_ACKNOWLEDGED;
Expand All @@ -87,6 +93,8 @@ public function runNextJob($connectionName, $queueNames, WorkerOptions $options)
return;
}

$this->startTime = hrtime(true);

$context = $this->queue->getQueueInteropContext();

$queueConsumer = new QueueConsumer($context, new ChainExtension($this->getAllExtensions([
Expand All @@ -96,6 +104,7 @@ public function runNextJob($connectionName, $queueNames, WorkerOptions $options)

foreach (explode(',', $queueNames) as $queueName) {
$queueConsumer->bindCallback($queueName, function() {
$this->processed++;
$this->runJob($this->job, $this->connectionName, $this->options);

return Result::ALREADY_ACKNOWLEDGED;
Expand Down Expand Up @@ -143,7 +152,7 @@ public function onMessageReceived(MessageReceived $context): void

public function onPostMessageReceived(PostMessageReceived $context): void
{
$this->stopIfNecessary($this->options, $this->lastRestart, $this->job);
$this->stopIfNecessary($this->options, $this->lastRestart, $this->startTime, $this->processed, $this->job);

if ($this->stopped) {
$context->interruptExecution();
Expand Down