-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfiledQueueWorker.php
More file actions
105 lines (85 loc) · 2.18 KB
/
ProfiledQueueWorker.php
File metadata and controls
105 lines (85 loc) · 2.18 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
<?php
namespace Perfbase\Drupal\Queue;
use Drupal\Core\Queue\QueueWorkerInterface;
use Perfbase\Drupal\Config\ConfigResolver;
use Perfbase\Drupal\Lifecycle\QueueItemLifecycle;
use Perfbase\Drupal\Runtime\PerfbaseFactoryInterface;
use Perfbase\Drupal\Support\ErrorHandler;
/**
*
*/
class ProfiledQueueWorker implements QueueWorkerInterface {
private QueueWorkerInterface $inner;
private string $pluginId;
private PerfbaseFactoryInterface $factory;
private ConfigResolver $configResolver;
private ErrorHandler $errorHandler;
public function __construct(
QueueWorkerInterface $inner,
string $pluginId,
PerfbaseFactoryInterface $factory,
ConfigResolver $configResolver,
ErrorHandler $errorHandler,
) {
$this->inner = $inner;
$this->pluginId = $pluginId;
$this->factory = $factory;
$this->configResolver = $configResolver;
$this->errorHandler = $errorHandler;
}
/**
* @param mixed $data
*/
public function processItem($data): void {
$lifecycle = new QueueItemLifecycle(
$this->pluginId,
$this->factory,
$this->configResolver,
$this->errorHandler
);
$lifecycle->startProfiling();
try {
$this->inner->processItem($data);
}
catch (\Throwable $exception) {
$lifecycle->setException($exception->getMessage());
throw $exception;
} finally {
$lifecycle->stopProfiling();
}
}
/**
*
*/
public function getPluginId(): string {
return (string) $this->inner->getPluginId();
}
/**
* @return array<string, mixed>
*/
public function getPluginDefinition(): array {
$definition = $this->inner->getPluginDefinition();
return is_array($definition) ? $definition : [];
}
/**
*
*/
public function getBaseId(): string {
$parts = explode(':', $this->pluginId, 2);
return $parts[0];
}
/**
*
*/
public function getDerivativeId(): ?string {
$parts = explode(':', $this->pluginId, 2);
return $parts[1] ?? NULL;
}
/**
* @param array<int, mixed> $arguments
* @return mixed
*/
public function __call(string $name, array $arguments) {
return $this->inner->{$name}(...$arguments);
}
}