blob: 4ccea4f812f083e46a36d2503886e84c6806f5a4 (
plain)
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
|
<?php
/**
* @var Goridge\RelayInterface $relay
*/
use Spiral\Goridge;
use Spiral\RoadRunner;
use Spiral\Goridge\StreamRelay;
require __DIR__ . "/vendor/autoload.php";
$rr = new RoadRunner\Worker(new StreamRelay(\STDIN, \STDOUT));
while ($in = $rr->waitPayload()) {
try {
$ctx = json_decode($in->header, true);
$headers = $ctx['headers'];
$set = isset($headers['attempts']);
$val = 0;
if ($set == true) {
$val = intval($headers['attempts'][0]);
$val++;
$headers['attempts'][0] = strval($val);
} else {
$headers['attempts'][0] = "1";
};
if ($val > 3) {
$rr->respond(new RoadRunner\Payload(json_encode([
// no error
'type' => 0,
'data' => []
])));
} else {
$rr->respond(new RoadRunner\Payload(json_encode([
'type' => 1,
'data' => [
'message' => 'error',
'requeue' => true,
'delay_seconds' => 5,
'headers' => $headers
]
])));
}
} catch (\Throwable $e) {
$rr->error((string)$e);
}
}
|