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 0fd1f3f

Browse files
committed
laravel-queue-replaceable
1 parent edcc065 commit 0fd1f3f

File tree

4 files changed

+66
-26
lines changed

4 files changed

+66
-26
lines changed

‎README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ return [
4949
```php
5050
<?php
5151

52+
namespace App\Jobs;
53+
54+
class ProcessPodcast implements ShouldQueue
55+
{
56+
57+
public function getReplaceableId()
58+
{
59+
return 'replaceable-id';
60+
}
61+
62+
}
63+
```
64+
65+
```php
66+
<?php
67+
68+
use App\Jobs\ProcessPodcast;
69+
5270
ProcessPodcast::dispatch($podcast)
5371
->onConnection('replaceable_database')
5472
->delay(now()->addMinutes(10));

‎src/DatabaseQueue.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
class DatabaseQueue extends BaseDatabaseQueue
88
{
99

10+
use QueueReplaceable;
11+
1012
/**
1113
* Push an array of jobs onto the queue.
1214
*

‎src/QueueReplaceable.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Alone\LaravelQueueReplaceable;
4+
5+
trait QueueReplaceable
6+
{
7+
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)
17+
{
18+
return $this->createPayloadArrayReplaceable($job,$data,$queue);
19+
}
20+
21+
public function getJobReplaceableId($job,$data = '',$queue = null)
22+
{
23+
$replaceableId = null;
24+
if(is_object($job) && method_exists($job,'getReplaceableId'))
25+
{
26+
$replaceableId = $job->getReplaceableId();
27+
}
28+
elseif(is_array($data) || is_object($data))
29+
{
30+
$replaceableId = (string)data_get($data,'replaceable');
31+
}
32+
return $replaceableId;
33+
}
34+
35+
public function createPayloadArrayReplaceable($job,$data = '',$queue = null)
36+
{
37+
$payload = parent::createPayloadArray($job,$data,$queue);
38+
if($replaceableId = $this->getJobReplaceableId($job,$data,$queue))
39+
{
40+
data_set($payload,'id',$replaceableId);
41+
}
42+
return $payload;
43+
}
44+
45+
}

‎src/RedisQueue.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,6 @@
77
class RedisQueue extends BaseRedisQueue
88
{
99

10-
/**
11-
* Create a payload string from the given job and data.
12-
*
13-
* @param string $job
14-
* @param mixed $data
15-
* @param string $queue
16-
* @return array
17-
*/
18-
protected function createPayloadArray($job, $data = '', $queue = null)
19-
{
20-
$payload = parent::createPayloadArray($job,$data,$queue);
21-
$replaceableId = null;
22-
if(is_object($job) && method_exists($job,'getReplaceableId'))
23-
{
24-
$replaceableId = $job->getReplaceableId();
25-
}
26-
elseif(is_array($data) || is_object($data))
27-
{
28-
$replaceableId = (string)data_get($data,'replaceable');
29-
}
30-
if($replaceableId)
31-
{
32-
data_set($payload,'id',$replaceableId);
33-
}
34-
return $payload;
35-
}
10+
use QueueReplaceable;
3611

3712
}

0 commit comments

Comments
(0)

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