Skip to content

Commit a6b13a9

Browse files
committed
enqueue all jobs using a enqueueUsing method
1 parent 7ca3df6 commit a6b13a9

File tree

5 files changed

+49
-21
lines changed

5 files changed

+49
-21
lines changed

src/Illuminate/Queue/BeanstalkdQueue.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public function size($queue = null)
7777
*/
7878
public function push($job, $data = '', $queue = null)
7979
{
80-
return $this->pushRaw($this->createPayload($job, $this->getQueue($queue), $data), $queue);
80+
return $this->enqueueUsing($job, function () use ($data, $queue, $job) {
81+
return $this->pushRaw($this->createPayload($job, $this->getQueue($queue), $data), $queue);
82+
});
8183
}
8284

8385
/**
@@ -108,12 +110,14 @@ public function later($delay, $job, $data = '', $queue = null)
108110
{
109111
$pheanstalk = $this->pheanstalk->useTube($this->getQueue($queue));
110112

111-
return $pheanstalk->put(
112-
$this->createPayload($job, $this->getQueue($queue), $data),
113-
Pheanstalk::DEFAULT_PRIORITY,
114-
$this->secondsUntil($delay),
115-
$this->timeToRun
116-
);
113+
return $this->enqueueUsing($job, function () use ($delay, $pheanstalk, $data, $queue, $job) {
114+
return $pheanstalk->put(
115+
$this->createPayload($job, $this->getQueue($queue), $data),
116+
Pheanstalk::DEFAULT_PRIORITY,
117+
$this->secondsUntil($delay),
118+
$this->timeToRun
119+
);
120+
});
117121
}
118122

119123
/**

src/Illuminate/Queue/DatabaseQueue.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ public function size($queue = null)
8080
*/
8181
public function push($job, $data = '', $queue = null)
8282
{
83-
return $this->pushToDatabase($queue, $this->createPayload(
84-
$job, $this->getQueue($queue), $data
85-
));
83+
return $this->enqueueUsing($job, function () use ($data, $queue, $job) {
84+
return $this->pushToDatabase($queue, $this->createPayload(
85+
$job, $this->getQueue($queue), $data
86+
));
87+
});
8688
}
8789

8890
/**
@@ -109,9 +111,11 @@ public function pushRaw($payload, $queue = null, array $options = [])
109111
*/
110112
public function later($delay, $job, $data = '', $queue = null)
111113
{
112-
return $this->pushToDatabase($queue, $this->createPayload(
113-
$job, $this->getQueue($queue), $data
114-
), $delay);
114+
return $this->enqueueUsing($job, function () use ($delay, $data, $queue, $job) {
115+
return $this->pushToDatabase($queue, $this->createPayload(
116+
$job, $this->getQueue($queue), $data
117+
), $delay);
118+
});
115119
}
116120

117121
/**

src/Illuminate/Queue/Queue.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ protected function withCreatePayloadHooks($queue, array $payload)
256256
return $payload;
257257
}
258258

259+
/**
260+
* Enqueue a job using the given callback.
261+
*
262+
* @param callable $callback
263+
* @param \Closure|string|object $job
264+
* @return mixed
265+
*/
266+
protected function enqueueUsing($job, $callback)
267+
{
268+
return call_user_func($callback);
269+
}
270+
259271
/**
260272
* Get the connection name for the queue.
261273
*

src/Illuminate/Queue/RedisQueue.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ public function bulk($jobs, $data = '', $queue = null)
108108
*/
109109
public function push($job, $data = '', $queue = null)
110110
{
111-
return $this->pushRaw($this->createPayload($job, $this->getQueue($queue), $data), $queue);
111+
return $this->enqueueUsing($job, function () use ($data, $queue, $job) {
112+
return $this->pushRaw($this->createPayload($job, $this->getQueue($queue), $data), $queue);
113+
});
112114
}
113115

114116
/**
@@ -140,7 +142,9 @@ public function pushRaw($payload, $queue = null, array $options = [])
140142
*/
141143
public function later($delay, $job, $data = '', $queue = null)
142144
{
143-
return $this->laterRaw($delay, $this->createPayload($job, $this->getQueue($queue), $data), $queue);
145+
return $this->enqueueUsing($job, function () use ($delay, $data, $queue, $job) {
146+
return $this->laterRaw($delay, $this->createPayload($job, $this->getQueue($queue), $data), $queue);
147+
});
144148
}
145149

146150
/**

src/Illuminate/Queue/SqsQueue.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public function size($queue = null)
8383
*/
8484
public function push($job, $data = '', $queue = null)
8585
{
86-
return $this->pushRaw($this->createPayload($job, $queue ?: $this->default, $data), $queue);
86+
return $this->enqueueUsing($job, function () use ($data, $queue, $job) {
87+
return $this->pushRaw($this->createPayload($job, $queue ?: $this->default, $data), $queue);
88+
});
8789
}
8890

8991
/**
@@ -112,11 +114,13 @@ public function pushRaw($payload, $queue = null, array $options = [])
112114
*/
113115
public function later($delay, $job, $data = '', $queue = null)
114116
{
115-
return $this->sqs->sendMessage([
116-
'QueueUrl' => $this->getQueue($queue),
117-
'MessageBody' => $this->createPayload($job, $queue ?: $this->default, $data),
118-
'DelaySeconds' => $this->secondsUntil($delay),
119-
])->get('MessageId');
117+
return $this->enqueueUsing($job, function () use ($delay, $data, $queue, $job) {
118+
return $this->sqs->sendMessage([
119+
'QueueUrl' => $this->getQueue($queue),
120+
'MessageBody' => $this->createPayload($job, $queue ?: $this->default, $data),
121+
'DelaySeconds' => $this->secondsUntil($delay),
122+
])->get('MessageId');
123+
});
120124
}
121125

122126
/**

0 commit comments

Comments
 (0)