Skip to content

Commit 73c23c5

Browse files
committed
Added support of plain handlers
1 parent 2e99304 commit 73c23c5

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/Jobs/PubSubJob.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,34 @@ public function getJobId()
6868
*/
6969
public function getRawBody()
7070
{
71+
if ($this->pubsub->checkHandler($this->subscriber)) {
72+
return $this->modifyPayload(
73+
$this->job->data(),
74+
$this->pubsub->getHandler($this->subscriber)
75+
);
76+
}
7177
return base64_decode($this->job->data());
7278
}
7379

80+
/**
81+
* @param string|array $payload
82+
* @param string $class
83+
* @return array
84+
*/
85+
private function modifyPayload($payload, $class)
86+
{
87+
if (!is_array($payload)) {
88+
$payload = json_decode($payload, true);
89+
}
90+
91+
$body = [
92+
'job' => $class . '@handle',
93+
'data' => $payload,
94+
];
95+
96+
return json_encode($body);
97+
}
98+
7499
/**
75100
* Delete the job from the queue.
76101
*

src/PubSubQueue.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,39 @@ public function size($subscriber = null)
6363
return 0;
6464
}
6565

66+
/**
67+
* Check whether handler exist
68+
*
69+
* @param string $queue
70+
*
71+
* @return bool
72+
*/
73+
public function checkHandler($subscriber)
74+
{
75+
if (array_key_exists('plain_handlers', $this->config)) {
76+
return array_key_exists($subscriber, $this->config['plain_handlers']);
77+
}
78+
return false;
79+
}
80+
81+
/**
82+
* Check whether handler exist
83+
*
84+
* @param string $queue
85+
*
86+
* @return string
87+
*/
88+
public function getHandler($subscriber)
89+
{
90+
return $this->config['plain_handlers'][$subscriber];
91+
}
92+
6693
/**
6794
* Push a new job onto the queue.
6895
*
6996
* @param string|object $job
7097
* @param mixed $data
71-
* @param string $queue
98+
* @param string $subscriber
7299
*
73100
* @return mixed
74101
*/
@@ -81,7 +108,7 @@ public function push($job, $data = '', $subscriber = null)
81108
* Push a raw payload onto the queue.
82109
*
83110
* @param string $payload
84-
* @param string $queue
111+
* @param string $subscriber
85112
* @param array $options
86113
*
87114
* @return array

0 commit comments

Comments
 (0)