@@ -17,7 +17,8 @@ |
||
17 | 17 | * |
18 | 18 | * @see https://github.com/symplify/symplify/issues/2061 |
19 | 19 | */ |
20 | -register_shutdown_function(static function () { |
|
20 | +register_shutdown_function(static function () |
|
21 | +{ |
|
21 | 22 | $dest = json_decode(file_get_contents(__DIR__ . '/composer.json'), true); |
22 | 23 | |
23 | 24 | $result = [ |
@@ -26,7 +26,8 @@ discard block |
||
26 | 26 | { |
27 | 27 | $dotenvPath = $env->get('DOTENV_PATH', $dirs->get('root') . '.env'); |
28 | 28 | |
29 | - if (!file_exists($dotenvPath)) { |
|
29 | + if (!file_exists($dotenvPath)) |
|
30 | + { |
|
30 | 31 | return; |
31 | 32 | } |
32 | 33 | |
@@ -36,7 +37,8 @@ discard block |
||
36 | 37 | ) |
37 | 38 | ->load(); |
38 | 39 | |
39 | - foreach ($dotenv as $key => $value) { |
|
40 | + foreach ($dotenv as $key => $value) |
|
41 | + { |
|
40 | 42 | $env->set($key, $value); |
41 | 43 | } |
42 | 44 | } |
@@ -80,14 +80,20 @@ discard block |
||
80 | 80 | { |
81 | 81 | /** @var Http $http */ |
82 | 82 | $http = $this->container->get(Http::class); |
83 | - while ($request = $this->worker->waitRequest()) { |
|
84 | - try { |
|
83 | + while ($request = $this->worker->waitRequest()) |
|
84 | + { |
|
85 | + try |
|
86 | + { |
|
85 | 87 | $response = $http->handle($request); |
86 | 88 | |
87 | 89 | $this->worker->respond($response); |
88 | - } catch (\Throwable $e) { |
|
90 | + } |
|
91 | + catch (\Throwable $e) |
|
92 | + { |
|
89 | 93 | $this->worker->respond($this->errorToResponse($e)); |
90 | - } finally { |
|
94 | + } |
|
95 | + finally |
|
96 | + { |
|
91 | 97 | $this->finalizer->finalize(false); |
92 | 98 | } |
93 | 99 | } |
@@ -101,7 +107,8 @@ discard block |
||
101 | 107 | { |
102 | 108 | $handler = new HtmlHandler(); |
103 | 109 | |
104 | - try { |
|
110 | + try |
|
111 | + { |
|
105 | 112 | /** @var SnapshotInterface $snapshot */ |
106 | 113 | $snapshot = $this->container->get(SnapshotterInterface::class)->register($e); |
107 | 114 | \file_put_contents('php://stderr', $snapshot->getMessage()); |
@@ -109,10 +116,13 @@ discard block |
||
109 | 116 | // on demand |
110 | 117 | $state = $this->container->get(StateInterface::class); |
111 | 118 | |
112 | - if ($state !== null) { |
|
119 | + if ($state !== null) |
|
120 | + { |
|
113 | 121 | $handler = $handler->withState($state); |
114 | 122 | } |
115 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
123 | + } |
|
124 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
125 | + { |
|
116 | 126 | \file_put_contents('php://stderr', (string)$e); |
117 | 127 | } |
118 | 128 |
@@ -23,7 +23,8 @@ |
||
23 | 23 | { |
24 | 24 | protected function tearDown(): void |
25 | 25 | { |
26 | - if (file_exists(Job::JOB_FILE)) { |
|
26 | + if (file_exists(Job::JOB_FILE)) |
|
27 | + { |
|
27 | 28 | unlink(Job::JOB_FILE); |
28 | 29 | } |
29 | 30 | } |
@@ -35,7 +35,8 @@ discard block |
||
35 | 35 | |
36 | 36 | protected function tearDown(): void |
37 | 37 | { |
38 | - if (file_exists((static::JOB)::JOB_FILE)) { |
|
38 | + if (file_exists((static::JOB)::JOB_FILE)) |
|
39 | + { |
|
39 | 40 | unlink((static::JOB)::JOB_FILE); |
40 | 41 | } |
41 | 42 | } |
@@ -105,7 +106,8 @@ discard block |
||
105 | 106 | { |
106 | 107 | $start = microtime(true); |
107 | 108 | $try = 0; |
108 | - while (!file_exists($this->job::JOB_FILE) && $try < 10) { |
|
109 | + while (!file_exists($this->job::JOB_FILE) && $try < 10) |
|
110 | + { |
|
109 | 111 | usleep(250000); |
110 | 112 | $try++; |
111 | 113 | } |
@@ -43,10 +43,13 @@ |
||
43 | 43 | $method = new \ReflectionMethod($this, static::HANDLE_FUNCTION); |
44 | 44 | $method->setAccessible(true); |
45 | 45 | |
46 | - try { |
|
46 | + try |
|
47 | + { |
|
47 | 48 | $parameters = array_merge(['payload' => $payloadData, 'id' => $jobID], $payloadData); |
48 | 49 | $method->invokeArgs($this, $this->resolver->resolveArguments($method, $parameters)); |
49 | - } catch (\Throwable $e) { |
|
50 | + } |
|
51 | + catch (\Throwable $e) |
|
52 | + { |
|
50 | 53 | throw new JobException( |
51 | 54 | sprintf('[%s] %s', get_class($this), $e->getMessage()), |
52 | 55 | $e->getCode(), |
@@ -50,13 +50,17 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getHandler(string $jobType): HandlerInterface |
52 | 52 | { |
53 | - try { |
|
53 | + try |
|
54 | + { |
|
54 | 55 | $handler = $this->container->get($this->className($jobType)); |
55 | - } catch (ContainerException $e) { |
|
56 | + } |
|
57 | + catch (ContainerException $e) |
|
58 | + { |
|
56 | 59 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
57 | 60 | } |
58 | 61 | |
59 | - if (!$handler instanceof HandlerInterface) { |
|
62 | + if (!$handler instanceof HandlerInterface) |
|
63 | + { |
|
60 | 64 | throw new JobException("Unable to resolve job handler for `{$jobType}`"); |
61 | 65 | } |
62 | 66 | |
@@ -69,13 +73,17 @@ discard block |
||
69 | 73 | */ |
70 | 74 | public function getSerializer(string $jobType): SerializerInterface |
71 | 75 | { |
72 | - try { |
|
76 | + try |
|
77 | + { |
|
73 | 78 | $handler = $this->getHandler($jobType); |
74 | - } catch (JobException $e) { |
|
79 | + } |
|
80 | + catch (JobException $e) |
|
81 | + { |
|
75 | 82 | return $this->defaultSerializer; |
76 | 83 | } |
77 | 84 | |
78 | - if ($handler instanceof SerializerInterface) { |
|
85 | + if ($handler instanceof SerializerInterface) |
|
86 | + { |
|
79 | 87 | return $handler; |
80 | 88 | } |
81 | 89 | |
@@ -89,7 +97,8 @@ discard block |
||
89 | 97 | private function className(string $jobType): string |
90 | 98 | { |
91 | 99 | $names = explode('.', $jobType); |
92 | - $names = array_map(function (string $value) { |
|
100 | + $names = array_map(function (string $value) |
|
101 | + { |
|
93 | 102 | return $this->inflector->classify($value); |
94 | 103 | }, $names); |
95 | 104 |
@@ -37,18 +37,25 @@ |
||
37 | 37 | */ |
38 | 38 | public function serve(Worker $worker, callable $finalize = null): void |
39 | 39 | { |
40 | - while ($body = $worker->receive($context)) { |
|
41 | - try { |
|
40 | + while ($body = $worker->receive($context)) |
|
41 | + { |
|
42 | + try |
|
43 | + { |
|
42 | 44 | $context = json_decode($context, true); |
43 | 45 | $handler = $this->registry->getHandler($context['job']); |
44 | 46 | |
45 | 47 | $handler->handle($context['job'], $context['id'], $body); |
46 | 48 | |
47 | 49 | $worker->send('ok'); |
48 | - } catch (\Throwable $e) { |
|
50 | + } |
|
51 | + catch (\Throwable $e) |
|
52 | + { |
|
49 | 53 | $worker->error((string)$e->getMessage()); |
50 | - } finally { |
|
51 | - if ($finalize !== null) { |
|
54 | + } |
|
55 | + finally |
|
56 | + { |
|
57 | + if ($finalize !== null) |
|
58 | + { |
|
52 | 59 | call_user_func($finalize, $e ?? null); |
53 | 60 | } |
54 | 61 | } |
@@ -40,7 +40,8 @@ |
||
40 | 40 | public function push(string $jobType, array $payload = [], Options $options = null): string |
41 | 41 | { |
42 | 42 | $payloadBody = $this->serialize($jobType, $payload); |
43 | - if ($options !== null && $options->getDelay()) { |
|
43 | + if ($options !== null && $options->getDelay()) |
|
44 | + { |
|
44 | 45 | sleep($options->getDelay()); |
45 | 46 | } |
46 | 47 |