Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a3f860d

Browse files
committed
laravel-queue-replaceable
1 parent eb5b16a commit a3f860d

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

‎src/QueueReplaceable.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
trait QueueReplaceable
66
{
77

8-
/**
9-
* Create a payload string from the given job and data.
10-
*
11-
* @param string $job
12-
* @param mixed $data
13-
* @param string $queue
14-
* @return array
15-
*/
16-
protected function createPayloadArray($job, $data = '', $queue = null)
8+
protected function createPayload($job,$data = '',$queue = null)
9+
{
10+
return parent::createPayload($this->getReplaceableJob($job),$data,$queue);
11+
}
12+
13+
protected function createPayloadArray($job,$data = '',$queue = null)
1714
{
1815
return $this->createPayloadArrayReplaceable($job,$data,$queue);
1916
}
@@ -42,4 +39,18 @@ public function createPayloadArrayReplaceable($job,$data = '',$queue = null)
4239
return $payload;
4340
}
4441

42+
public function getReplaceableJob($job)
43+
{
44+
$replaceableJob = $job;
45+
if(is_object($job))
46+
{
47+
$replaceableJob = clone $job;
48+
if(method_exists($replaceableJob,'delay'))
49+
{
50+
$replaceableJob->delay(null);
51+
}
52+
}
53+
return $replaceableJob;
54+
}
55+
4556
}

‎src/ServiceProvider.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,20 @@
22

33
namespace Alone\LaravelQueueReplaceable;
44

5-
use Illuminate\Support\Facades\Queue;
6-
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
5+
use Illuminate\Support;
76

8-
class ServiceProvider extends BaseServiceProvider
7+
class ServiceProvider extends Support\ServiceProvider
98
{
109

11-
/**
12-
* Indicates if loading of the provider is deferred.
13-
*
14-
* @var bool
15-
*/
16-
protected $defer = true;
17-
18-
public function register()
10+
public function boot()
1911
{
20-
Queue::extend('replaceable_database',function()
12+
/** @var \Illuminate\Queue\QueueManager $queue */
13+
$queue = $this->app['queue'];
14+
$queue->addConnector('replaceable_database',function()
2115
{
2216
return new Connectors\DatabaseConnector($this->app['db']);
2317
});
24-
Queue::extend('replaceable_redis',function()
18+
$queue->addConnector('replaceable_redis',function()
2519
{
2620
return new Connectors\RedisConnector($this->app['redis']);
2721
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /