forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThrowSignalEvent.php
More file actions
81 lines (71 loc) · 2.43 KB
/
ThrowSignalEvent.php
File metadata and controls
81 lines (71 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace ProcessMaker\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use ProcessMaker\Facades\WorkflowManager;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessRequest;
class ThrowSignalEvent implements ShouldQueue
{
use Dispatchable,
InteractsWithQueue,
Queueable;
private const maxJobs = 10;
public $signalRef;
public $data_uid;
public $excludeProcesses;
public $excludeRequests;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($signalRef, array $data = [], array $excludeProcesses = [], array $excludeRequests = [])
{
$this->signalRef = $signalRef;
$this->data_uid = packTemporalData($data);
$this->excludeProcesses = $excludeProcesses;
$this->excludeRequests = $excludeRequests;
}
public function handle()
{
$this->data = unpackTemporalData($this->data_uid);
$processes = Process::whereNotIn('id', $this->excludeProcesses)
->whereJsonContains('signal_events', $this->signalRef)
->where('status', 'ACTIVE')
->pluck('id')
->toArray();
foreach ($processes as $process) {
WorkflowManager::throwSignalEventProcess(
$process,
$this->signalRef,
$this->data
);
}
$count = ProcessRequest::whereNotIn('id', $this->excludeRequests)
->where('status', 'ACTIVE')
->whereJsonContains('signal_events', $this->signalRef)
->count();
if ($count) {
$perJob = ceil($count / self::maxJobs);
$requests = ProcessRequest::select(['id'])
->whereJsonContains('signal_events', $this->signalRef)
->where('status', 'ACTIVE')
->whereNotIn('id', $this->excludeRequests);
$requests = $requests->orderBy('id')
->pluck('id')
->toArray();
$chunks = array_chunk($requests, $perJob);
foreach ($chunks as $chunk) {
CatchSignalEventRequest::dispatch(
$chunk,
$this->signalRef,
$this->data
)->onQueue('bpmn');
}
}
removeTemporalData($this->data_uid);
}
}