summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-04-20 12:36:07 +0300
committerValery Piashchynski <[email protected]>2020-04-20 12:36:07 +0300
commit325dd39b610726df4b0ea7f70f5e475ffe63062d (patch)
tree97d8d54c5752d85ba31ac2fc7ad6f399cbf2bf70 /src
parent540e0ec01382a23221f0e8e359e756b15c1216f7 (diff)
save
Diffstat (limited to 'src')
-rw-r--r--src/Worker.php33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/Worker.php b/src/Worker.php
index 35294221..5a567677 100644
--- a/src/Worker.php
+++ b/src/Worker.php
@@ -72,6 +72,26 @@ class Worker
return $body;
}
+// /**
+// * Respond to the server with result of task execution and execution context.
+// *
+// * Example:
+// * $worker->respond((string)$response->getBody(), json_encode($response->getHeaders()));
+// *
+// * @param string|null $payload
+// * @param string|null $header
+// */
+// public function send(string $payload = null, string $header = null): void
+// {
+// if ($header === null) {
+// $this->relay->send('', Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE);
+// } else {
+// $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW);
+// }
+//
+// $this->relay->send((string) $payload, Relay::PAYLOAD_RAW);
+// }
+
/**
* Respond to the server with result of task execution and execution context.
*
@@ -83,15 +103,14 @@ class Worker
*/
public function send(string $payload = null, string $header = null): void
{
- if ($header === null) {
- $this->relay->send('', Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE);
- } else {
- $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW);
- }
+ $flag = Relay::PAYLOAD_CONTROL;
+ $flag = $flag | (empty($header) ? Relay::PAYLOAD_NONE : Relay::PAYLOAD_RAW);
- $this->relay->send((string) $payload, Relay::PAYLOAD_RAW);
- }
+ $head = pack('', $header, $flag);
+ $body = pack('', $payload, Relay::PAYLOAD_RAW);
+ $this->relay->send($head . $body);
+ }
/**
* Respond to the server with an error. Error must be treated as TaskError and might not cause
* worker destruction.