Skip to content

Commit c98c9fa

Browse files
committedMay 29, 2018
Fixed executed jobs limit to follow yiisoft/yii2-queue API changes
1 parent 482bf32 commit c98c9fa

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed
 

‎src/console/QueueController.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use yii\queue\ErrorEvent;
2121
use yii\queue\JobEvent;
2222
use yii\queue\Queue;
23+
use yii\queue\cli\Queue as CliQueue;
2324

2425
/**
2526
* Manages service Queue.
@@ -71,10 +72,11 @@ public function actionTestErrorHandler()
7172

7273
private function ensureLimits()
7374
{
74-
if (++$this->executedJobsCount >= static::MAX_EXECUTED_JOBS && function_exists('posix_kill')) {
75-
$this->stdout('Reached limit of ' . static::MAX_EXECUTED_JOBS . " executed jobs. Stopping process.\n");
76-
Signal::setExitFlag();
75+
if ($this->executedJobsCount++ > static::MAX_EXECUTED_JOBS && function_exists('posix_kill')) {
76+
return 15; // SIGTERM
7777
}
78+
79+
return null;
7880
}
7981

8082
/**
@@ -102,6 +104,14 @@ private function attachEventHandlers()
102104
$out("%RJob '" . get_class($event->job) . "' finished with error:%n '" . $event->error . "'\n");
103105
});
104106

107+
Event::on(Queue::class, CliQueue::EVENT_WORKER_LOOP, function (\yii\queue\cli\WorkerEvent $event) use ($out) {
108+
$exitCode = $this->ensureLimits();
109+
if ($exitCode !== null) {
110+
$out('Reached limit of ' . static::MAX_EXECUTED_JOBS . " executed jobs. Stopping process.\n");
111+
$event->exitCode = $exitCode;
112+
}
113+
});
114+
105115
Event::on(AbstractPackageCommand::class, AbstractPackageCommand::EVENT_BEFORE_RUN, function ($event) use ($out) {
106116
/** @var AbstractPackageCommand $command */
107117
$command = $event->sender;

0 commit comments

Comments
 (0)
Failed to load comments.