-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathProcessManager.php
More file actions
730 lines (647 loc) · 26.7 KB
/
Copy pathProcessManager.php
File metadata and controls
730 lines (647 loc) · 26.7 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
<?php declare(strict_types=1);
/*
* This file is part of the CleverAge/ProcessBundle package.
*
* Copyright (C) 2017-2021 Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CleverAge\ProcessBundle\Manager;
use CleverAge\ProcessBundle\Configuration\ProcessConfiguration;
use CleverAge\ProcessBundle\Configuration\TaskConfiguration;
use CleverAge\ProcessBundle\Context\ContextualOptionResolver;
use CleverAge\ProcessBundle\Event\ProcessEvent;
use CleverAge\ProcessBundle\Exception\CircularProcessException;
use CleverAge\ProcessBundle\Exception\InvalidProcessConfigurationException;
use CleverAge\ProcessBundle\Exception\MissingTaskConfigurationException;
use CleverAge\ProcessBundle\Logger\ProcessLogger;
use CleverAge\ProcessBundle\Logger\TaskLogger;
use CleverAge\ProcessBundle\Model\BlockingTaskInterface;
use CleverAge\ProcessBundle\Model\FinalizableTaskInterface;
use CleverAge\ProcessBundle\Model\FlushableTaskInterface;
use CleverAge\ProcessBundle\Model\InitializableTaskInterface;
use CleverAge\ProcessBundle\Model\IterableTaskInterface;
use CleverAge\ProcessBundle\Model\ProcessHistory;
use CleverAge\ProcessBundle\Model\ProcessState;
use CleverAge\ProcessBundle\Model\TaskInterface;
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Psr\EventDispatcher\EventDispatcherInterface;
/**
* Execute processes
*
* @author Valentin Clavreul <vclavreul@clever-age.com>
* @author Vincent Chalnot <vchalnot@clever-age.com>
*/
class ProcessManager
{
protected const EXECUTE_PROCESS = 1;
protected const EXECUTE_PROCEED = 2;
protected const EXECUTE_FLUSH = 4;
/** @var ContainerInterface */
protected $container;
/** @var ProcessLogger */
protected $processLogger;
/** @var TaskLogger */
protected $taskLogger;
/** @var ProcessConfigurationRegistry */
protected $processConfigurationRegistry;
/** @var TaskConfiguration */
protected $blockingTaskConfiguration;
/** @var ContextualOptionResolver */
protected $contextualOptionResolver;
/** @var TaskConfiguration[] */
protected $processedIterables = [];
/** @var TaskConfiguration[] */
protected $processedBlockings = [];
/** @var ProcessHistory */
protected $processHistory;
/** @var TaskConfiguration */
protected $taskConfiguration;
/** @var EventDispatcherInterface */
protected $eventDispatcher;
/**
* ProcessManager constructor.
*
* @param ContainerInterface $container
* @param ProcessLogger $processLogger
* @param TaskLogger $taskLogger
* @param ProcessConfigurationRegistry $processConfigurationRegistry
* @param ContextualOptionResolver $contextualOptionResolver
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(
ContainerInterface $container,
ProcessLogger $processLogger,
TaskLogger $taskLogger,
ProcessConfigurationRegistry $processConfigurationRegistry,
ContextualOptionResolver $contextualOptionResolver,
EventDispatcherInterface $eventDispatcher
) {
$this->container = $container;
$this->processLogger = $processLogger;
$this->taskLogger = $taskLogger;
$this->processConfigurationRegistry = $processConfigurationRegistry;
$this->contextualOptionResolver = $contextualOptionResolver;
$this->eventDispatcher = $eventDispatcher;
}
/**
* @return ProcessHistory|null
*/
public function getProcessHistory(): ?ProcessHistory
{
return $this->processHistory;
}
/**
* @return TaskConfiguration|null
*/
public function getTaskConfiguration(): ?TaskConfiguration
{
return $this->taskConfiguration;
}
/**
* Execute a process with a given input and context
*
* This method decorates the real execution to add event & error handling
* @see ProcessManager::doExecute
*
* @param string $processCode
* @param null $input
* @param array $context
*
* @return mixed
*/
public function execute(string $processCode, $input = null, array $context = [])
{
try {
$this->eventDispatcher->dispatch(
new ProcessEvent($processCode, $input, $context),
ProcessEvent::EVENT_PROCESS_STARTED
);
$this->processLogger->debug('Process start');
$result = $this->doExecute($processCode, $input, $context);
$this->processLogger->debug('Process end');
$this->eventDispatcher->dispatch(
new ProcessEvent($processCode, $input, $context, $result),
ProcessEvent::EVENT_PROCESS_ENDED
);
} catch (\Throwable $error) {
$this->processLogger->critical('Critical process failure', ['error' => $error->getMessage()]);
$this->eventDispatcher->dispatch(
new ProcessEvent($processCode, $input, $context, null, $error),
ProcessEvent::EVENT_PROCESS_FAILED
);
throw $error;
}
return $result;
}
/**
* Real process execution, with a given input and context
*
* @param string $processCode
* @param mixed $input
* @param array $context
*
* @return mixed
*/
protected function doExecute(string $processCode, $input = null, array $context = [])
{
$parentProcessHistory = $this->processHistory;
$processConfiguration = $this->processConfigurationRegistry->getProcessConfiguration($processCode);
$processHistory = $this->initializeStates($processConfiguration, $context);
$this->processHistory = $processHistory;
$this->checkProcess($processConfiguration);
// First initialize the whole stack in a linear way, tasks are initialized in the order they are configured
foreach ($processConfiguration->getTaskConfigurations() as $taskConfiguration) {
$this->initialize($taskConfiguration);
}
// If defined, set the input of a task
if ($processConfiguration->getEntryPoint()) {
$processConfiguration->getEntryPoint()->getState()->setInput($input);
} elseif ($input !== null) {
$this->processLogger->warning('Process has no entry point for input');
}
// Resolve task from main branch, starting by the end
/** @var TaskConfiguration[] $taskList */
$taskList = array_reverse($processConfiguration->getTaskConfigurations());
$allowedTasks = $processConfiguration->getMainTaskGroup();
foreach ($taskList as $taskConfiguration) {
if (\in_array($taskConfiguration->getCode(), $allowedTasks, true)) {
$this->resolve($taskConfiguration);
}
}
// Finalize the process in a linear way
foreach ($processConfiguration->getTaskConfigurations() as $taskConfiguration) {
$this->finalize($taskConfiguration);
}
$this->endProcess($processHistory);
// If defined, return the output of a task
$returnValue = null;
if ($processConfiguration->getEndPoint()) {
$returnValue = $processConfiguration->getEndPoint()->getState()->getOutput();
}
$this->processHistory = $parentProcessHistory;
return $returnValue;
}
/**
* Resolve a task, by checking if parents are resolved and processing roots and BlockingTasks
*
* @param TaskConfiguration $taskConfiguration
*
* @throws \RuntimeException
* @throws \UnexpectedValueException
*
* @return bool
*/
protected function resolve(TaskConfiguration $taskConfiguration): bool
{
$state = $taskConfiguration->getState();
if ($state->isResolved()) {
return true;
}
$state->setStatus(ProcessState::STATUS_PENDING);
// Resolve parents first
$allParentsResolved = true;
foreach ($taskConfiguration->getPreviousTasksConfigurations() as $previousTasksConfiguration) {
if (!$previousTasksConfiguration->getState()->isResolved()) {
$isResolved = $this->resolve($previousTasksConfiguration);
$allParentsResolved = $allParentsResolved && $isResolved;
}
}
if (!$allParentsResolved) {
throw new \UnexpectedValueException('Cannot resolve all parents');
}
$state->setStatus(ProcessState::STATUS_PROCESSING);
// Start processing only roots that are not in error branch
if ($taskConfiguration->isRoot()) {
$this->process($taskConfiguration);
}
// Then we can proceed with BlockingTask only if they have been processed normally and where never "proceeded"
if ($taskConfiguration->getTask() instanceof BlockingTaskInterface
&& $this->hasProcessedBlocking($taskConfiguration)
) {
$this->process($taskConfiguration, self::EXECUTE_PROCEED);
}
// This task is now finished, we may flush it to test if there is anything lasting
$this->flush($taskConfiguration);
$state->setStatus(ProcessState::STATUS_RESOLVED);
return $state->isResolved();
}
/**
* Fetch task service and run additional setup for InitializableTasks
*
* @param TaskConfiguration $taskConfiguration
*
* @throws ServiceNotFoundException
* @throws ServiceCircularReferenceException
* @throws \UnexpectedValueException
* @throws \RuntimeException
*/
protected function initialize(TaskConfiguration $taskConfiguration): void
{
$this->taskConfiguration = $taskConfiguration;
if ($taskConfiguration->getErrorStrategy() === TaskConfiguration::STRATEGY_STOP
&& \count($taskConfiguration->getErrorOutputs()) > 0) {
$m = "Task configuration {$taskConfiguration->getCode()} has error outputs ";
$m .= "but it's error strategy 'stop' implies they will never be reached.";
$this->taskLogger->debug($m);
}
// @todo Refactor this using a Registry with this feature:
// https://symfony.com/doc/current/service_container/service_subscribers_locators.html
$serviceReference = $taskConfiguration->getServiceReference();
if (0 === strpos($serviceReference, '@')) {
$task = $this->container->get(ltrim($serviceReference, '@'));
} elseif ($this->container->has($serviceReference)) {
$task = $this->container->get($serviceReference);
} else {
throw new \UnexpectedValueException(
"Unable to resolve service reference for Task '{$taskConfiguration->getCode()}'"
);
}
if (!$task instanceof TaskInterface) {
throw new \UnexpectedValueException(
"Service defined in Task '{$taskConfiguration->getCode()}' is not a TaskInterface"
);
}
$taskConfiguration->setTask($task);
if ($task instanceof InitializableTaskInterface) {
$state = $taskConfiguration->getState();
try {
$task->initialize($state);
} catch (\Throwable $e) {
$logContext = ['exception' => $e];
$this->taskLogger->critical($e->getMessage(), $logContext);
$state->stop($e);
}
}
$this->handleState($taskConfiguration->getState());
$this->taskConfiguration = null;
}
/**
* @param TaskConfiguration $taskConfiguration
* @param int $executionFlag
*
* @throws \RuntimeException
*/
protected function process(TaskConfiguration $taskConfiguration, int $executionFlag = self::EXECUTE_PROCESS): void
{
$this->taskConfiguration = $taskConfiguration;
$state = $taskConfiguration->getState();
do {
// Execute the current task, and fetch status
$this->processExecution($taskConfiguration, $executionFlag);
$this->handleState($state);
// An error feed cannot be blocked or skipped (even if the process has been stopped)
if ($state->hasErrorOutput()) {
foreach ($taskConfiguration->getErrorTasksConfigurations() as $errorTask) {
$this->prepareNextProcess($taskConfiguration, $errorTask, true);
$this->process($errorTask);
// Bubble up the stop signal
if ($errorTask->getState()->isStopped()) {
$state->setStopped(true);
return;
}
}
}
if ($state->isStopped()) {
$exception = $state->getException();
if ($exception) {
$m = "Process {$state->getProcessConfiguration()->getCode()} has failed";
$m .= " during process {$state->getTaskConfiguration()->getCode()}";
$m .= " with message: '{$exception->getMessage()}'.\n";
throw new \RuntimeException($m, -1, $exception);
}
return;
}
// Run child items only if the state is not "skipped" and task is not blocking
$task = $taskConfiguration->getTask();
$shouldContinue =
(!$task instanceof BlockingTaskInterface || self::EXECUTE_PROCEED === $executionFlag)
&& !$state->isSkipped();
if ($shouldContinue) {
if ($task instanceof IterableTaskInterface) {
// Register the task as not empty
$this->addProcessedIterable($taskConfiguration);
}
foreach ($taskConfiguration->getNextTasksConfigurations() as $nextTaskConfiguration) {
$this->prepareNextProcess($taskConfiguration, $nextTaskConfiguration);
$this->process($nextTaskConfiguration);
// Bubble up the stop signal
if ($nextTaskConfiguration->getState()->isStopped()) {
$state->setStopped(true);
return;
}
}
$state->setSkipped(false); // Reset skipped state
}
$hasMoreItem = false; // By default, a task is not iterable
if ($task instanceof IterableTaskInterface) {
// Check if task has more items
$hasMoreItem = $task->next($state);
if (!$hasMoreItem) {
if (!$this->hasProcessedIterable($taskConfiguration)) {
return; // This means the task is empty
}
// This means we are over iterating this task so we can remove it from registry
$this->removeProcessedIterable($taskConfiguration);
if (self::EXECUTE_FLUSH !== $executionFlag) {
// This task is now finished, we may flush it to test if there is anything lasting
$this->flush($taskConfiguration);
}
if ($state->isStopped()) {
return;
}
}
}
} while ($hasMoreItem);
$this->taskConfiguration = null;
}
/**
* @param TaskConfiguration $taskConfiguration
* @param int $executionFlag
*/
protected function processExecution(TaskConfiguration $taskConfiguration, int $executionFlag): void
{
$task = $taskConfiguration->getTask();
if (null === $task) {
throw new \RuntimeException("Missing task for configuration {$taskConfiguration->getCode()}");
}
$state = $taskConfiguration->getState();
try {
if (self::EXECUTE_PROCESS === $executionFlag) {
$state->reset(false);
$this->processLogger->debug("Processing task {$taskConfiguration->getCode()}");
$task->execute($state);
if ($task instanceof BlockingTaskInterface) {
$this->addProcessedBlocking($taskConfiguration);
}
} elseif (self::EXECUTE_PROCEED === $executionFlag) {
$state->reset(true);
if (!$task instanceof BlockingTaskInterface) {
// This exception should never be thrown
throw new \UnexpectedValueException("Task {$taskConfiguration->getCode()} is not blocking");
}
$this->processLogger->debug("Proceeding task {$taskConfiguration->getCode()}");
$task->proceed($state);
$this->removeProcessedBlocking($taskConfiguration);
} elseif (self::EXECUTE_FLUSH === $executionFlag) {
$state->reset(true);
if (!$task instanceof FlushableTaskInterface) {
// This exception should never be thrown
throw new \UnexpectedValueException("Task {$taskConfiguration->getCode()} is not flushable");
}
$this->processLogger->debug("Flushing task {$taskConfiguration->getCode()}");
$task->flush($state);
} else {
throw new \UnexpectedValueException("Unknown execution flag: {$executionFlag}");
}
$exception = $state->getException();
} catch (\Throwable $e) {
$exception = $e;
}
// Manage exception catching and setting the same
if ($exception) {
$this->taskLogger->log(
$taskConfiguration->getLogLevel(),
$exception->getMessage(),
$state->getErrorContext()
);
$state->setException($exception);
if (!$state->hasErrorOutput()) {
$state->setErrorOutput($state->getInput());
}
if ($taskConfiguration->getErrorStrategy() === TaskConfiguration::STRATEGY_SKIP) {
$state->setSkipped(true);
} elseif ($taskConfiguration->getErrorStrategy() === TaskConfiguration::STRATEGY_STOP) {
$state->stop($exception);
} else {
throw new \UnexpectedValueException(
"Unknown error strategy '{$taskConfiguration->getErrorStrategy()}'"
);
}
}
}
/**
* Browse all children for FlushableTask until a BlockingTask is found
*
* @param TaskConfiguration $taskConfiguration
*
* @throws \RuntimeException
*/
protected function flush(TaskConfiguration $taskConfiguration): void
{
$task = $taskConfiguration->getTask();
if ($task instanceof BlockingTaskInterface) {
return;
}
if ($task instanceof FlushableTaskInterface) {
$this->process($taskConfiguration, self::EXECUTE_FLUSH);
if ($taskConfiguration->getState()->isStopped()) {
return;
}
}
// Check outputs
foreach ($taskConfiguration->getNextTasksConfigurations() as $nextTaskConfiguration) {
$this->flush($nextTaskConfiguration);
}
// Check errors
foreach ($taskConfiguration->getErrorTasksConfigurations() as $errorTasksConfiguration) {
$this->flush($errorTasksConfiguration);
}
}
/**
* @param TaskConfiguration $taskConfiguration
*
* @throws \RuntimeException
*/
protected function finalize(TaskConfiguration $taskConfiguration): void
{
$task = $taskConfiguration->getTask();
if ($task instanceof FinalizableTaskInterface) {
$this->taskConfiguration = $taskConfiguration;
$state = $taskConfiguration->getState();
try {
$task->finalize($taskConfiguration->getState());
} catch (\Throwable $e) {
$logContext = ['exception' => $e];
$this->taskLogger->critical($e->getMessage(), $logContext);
$state->stop($e);
}
$this->handleState($state);
$this->taskConfiguration = null;
}
}
/**
* @param ProcessConfiguration $processConfiguration
* @param array $context
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
*
* @return ProcessHistory
*/
protected function initializeStates(
ProcessConfiguration $processConfiguration,
array $context = []
): ProcessHistory {
$processHistory = new ProcessHistory($processConfiguration, $context);
foreach ($processConfiguration->getTaskConfigurations() as $taskConfiguration) {
$state = new ProcessState($processConfiguration, $processHistory);
$state->setContext($context);
$state->setContextualOptionResolver($this->contextualOptionResolver);
$taskConfiguration->setState($state);
$state->setTaskConfiguration($taskConfiguration);
}
return $processHistory;
}
/**
* @param TaskConfiguration $previousTaskConfiguration
* @param TaskConfiguration $nextTaskConfiguration
* @param bool $isError
*/
protected function prepareNextProcess(
TaskConfiguration $previousTaskConfiguration,
TaskConfiguration $nextTaskConfiguration,
$isError = false
): void {
if ($isError) {
$input = $previousTaskConfiguration->getState()->getErrorOutput();
} else {
$input = $previousTaskConfiguration->getState()->getOutput();
}
$nextState = $nextTaskConfiguration->getState();
$nextState->setInput($input);
$nextState->setPreviousState($previousTaskConfiguration->getState());
}
/**
* Save the state of the import process
*
* @param ProcessState $state
*
* @throws \RuntimeException
*/
protected function handleState(ProcessState $state): void
{
$processHistory = $state->getProcessHistory();
if ($state->getException() && $state->isStopped()) {
$processHistory->setFailed();
}
}
/**
* @param ProcessHistory $history
*
*/
protected function endProcess(ProcessHistory $history): void
{
// Do not change state if already set
if ($history->isStarted()) {
$history->setSuccess();
$this->processLogger->info(
"Process {$history->getProcessCode()} succeed",
[
'duration' => $history->getDuration(),
]
);
}
}
/**
* Validate a process
*
* @param ProcessConfiguration $processConfiguration
*
* @throws \RuntimeException
* @throws InvalidProcessConfigurationException
* @throws CircularProcessException
* @throws MissingTaskConfigurationException
*/
protected function checkProcess(ProcessConfiguration $processConfiguration): void
{
$processConfiguration->checkCircularDependencies();
$taskConfigurations = $processConfiguration->getTaskConfigurations();
$mainTaskList = $processConfiguration->getMainTaskGroup();
$entryPoint = $processConfiguration->getEntryPoint();
$endPoint = $processConfiguration->getEndPoint();
// Check multi-branch processes
foreach ($taskConfigurations as $taskConfiguration) {
if (!\in_array($taskConfiguration->getCode(), $mainTaskList, true)) {
// We won't throw an error to ease development... but there must be some kind of warning
$state = $taskConfiguration->getState();
$logContext = ['main_task_list' => $mainTaskList];
$this->processLogger->warning(
"Task '{$taskConfiguration->getCode()}' is unreachable, check that it's referenced in some other task output or in the main entry point",
$logContext
);
$this->handleState($state);
}
}
// Check coherence for entry/end points
$processConfiguration->getEndPoint();
if ($entryPoint && !\in_array($entryPoint->getCode(), $mainTaskList, true)) {
throw InvalidProcessConfigurationException::createNotInMain($processConfiguration, $entryPoint, $mainTaskList);
}
if ($endPoint && !\in_array($endPoint->getCode(), $mainTaskList, true)) {
throw InvalidProcessConfigurationException::createNotInMain($processConfiguration, $endPoint, $mainTaskList);
}
}
/**
* When an iterable task returns at least one element, it gets added here
*
* @param TaskConfiguration $taskConfiguration
*/
protected function addProcessedIterable(TaskConfiguration $taskConfiguration): void
{
$this->processedIterables[$taskConfiguration->getCode()] = $taskConfiguration;
}
/**
* If true this means that the tasks returned an element at least once
*
* @param TaskConfiguration $taskConfiguration
*
* @return bool
*/
protected function hasProcessedIterable(TaskConfiguration $taskConfiguration): bool
{
return array_key_exists($taskConfiguration->getCode(), $this->processedIterables);
}
/**
* Once everything was flushed, the task is resolved and can be removed from the stack
*
* @param TaskConfiguration $taskConfiguration
*/
protected function removeProcessedIterable(TaskConfiguration $taskConfiguration): void
{
unset($this->processedIterables[$taskConfiguration->getCode()]);
}
/**
* Add blocking tasks that were just processed
*
* @param TaskConfiguration $taskConfiguration
*/
protected function addProcessedBlocking(TaskConfiguration $taskConfiguration): void
{
$this->processedBlockings[$taskConfiguration->getCode()] = $taskConfiguration;
}
/**
* If true this means the task was processed normally but was never run with proceed
*
* @param TaskConfiguration $taskConfiguration
*
* @return bool
*/
protected function hasProcessedBlocking(TaskConfiguration $taskConfiguration): bool
{
return array_key_exists($taskConfiguration->getCode(), $this->processedBlockings);
}
/**
* Once a blocking task has been proceeded, we can remove it from the stack
*
* @param TaskConfiguration $taskConfiguration
*/
protected function removeProcessedBlocking(TaskConfiguration $taskConfiguration): void
{
unset($this->processedBlockings[$taskConfiguration->getCode()]);
}
}