1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\commands; |
4
|
|
|
|
5
|
|
|
use yii\console\Controller; |
6
|
|
|
use ReflectionClass; |
7
|
|
|
use Yii; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Handles processing of Queue Events |
11
|
|
|
*/ |
12
|
|
|
class QueueController extends Controller |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Main action to call for queue scanning |
16
|
|
|
* @param $queueName Defaults to the app queue |
17
|
|
|
*/ |
18
|
|
|
public function actionIndex($queueName = 'app') |
19
|
|
|
{ |
20
|
|
|
$queue = Yii::$app->queue->get()->queue($queueName); |
21
|
|
|
while (true) { |
22
|
|
|
try { |
23
|
|
|
$job = $queue->pull(1000); |
24
|
|
|
if (is_null($job)) { |
25
|
|
|
// There's nothing presently in the queue, so don't do anything |
26
|
|
|
if (YII_DEBUG) { |
27
|
|
|
Yii::info("There aren't any jobs in the queue. Waiting for additional jobs..."); |
28
|
|
|
} |
29
|
|
|
continue; |
30
|
|
|
} |
31
|
|
|
} catch (\Disque\Queue\JobNotAvailableException $e) { |
|
|
|
|
32
|
|
|
if (YII_DEBUG) { |
33
|
|
|
Yii::info("[" . date('Y-m-d H:i:s') . "] A scheduled job is available, but we should wait before running it."); |
34
|
|
|
} |
35
|
|
|
continue; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$body = $job->getBody(); |
39
|
|
|
if (!isset($body['class'])) { |
40
|
|
|
Yii::error("An error occured when trying to run an event with the following payload:" . print_r($body, true)); |
41
|
|
|
continue; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
try { |
45
|
|
|
$class = $body['class']; |
46
|
|
|
unset($body['class']); |
47
|
|
|
|
48
|
|
|
$event = new $class($body, $queue, $job); |
49
|
|
|
$reflect = new ReflectionClass($event); |
50
|
|
|
$eventName = $reflect->getShortName(); |
51
|
|
|
|
52
|
|
|
// Bind an event handler |
53
|
|
|
$this->on($eventName, function ($event) { |
54
|
|
|
$event->run(); |
55
|
|
|
// The event should be handled in some way, if it isn't, called the global event handler and mark it as processed |
56
|
|
|
if (!$event->handled) { |
57
|
|
|
$event->handled(); |
58
|
|
|
} |
59
|
|
|
}); |
60
|
|
|
|
61
|
|
|
// Trigger the event |
62
|
|
|
$this->trigger($eventName, $event); |
63
|
|
|
|
64
|
|
|
// Unbind the event handler |
65
|
|
|
$this->off($eventName); |
66
|
|
|
} catch (\Exception $e) { |
67
|
|
|
Yii::error("Event $class failed encountered an error: " . $e->getMessage()); |
68
|
|
|
$queue->processed($job); |
69
|
|
|
continue; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.