Skip to content

Commit f92db88

Browse files
committed
完善
1 parent 501dae9 commit f92db88

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"minimum-stability": "dev",
2525
"require": {
26+
"ext-json": "*",
2627
"topthink/think-helper": "^3.0.4",
2728
"topthink/framework": "^6.0.0",
2829
"topthink/think-factory": "^1.0.0",

src/queue/CallQueuedHandler.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@
1111

1212
namespace think\queue;
1313

14+
use think\App;
15+
1416
class CallQueuedHandler
1517
{
18+
protected $app;
19+
20+
public function __construct(App $app)
21+
{
22+
$this->app = $app;
23+
}
1624

1725
public function call(Job $job, array $data)
1826
{
1927
$command = unserialize($data['command']);
2028

21-
call_user_func([$command, 'handle']);
29+
$this->app->invoke([$command, 'handle']);
2230

2331
if (!$job->isDeletedOrReleased()) {
2432
$job->delete();

src/queue/Connector.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,16 @@ protected function createPlainPayload($job, $data)
8888

8989
protected function createObjectPayload($job)
9090
{
91-
$payload = [
91+
return [
9292
'job' => 'think\queue\CallQueuedHandler@call',
9393
'maxTries' => $job->tries ?? null,
9494
'timeout' => $job->timeout ?? null,
9595
'timeoutAt' => $this->getJobExpiration($job),
9696
'data' => [
97-
'commandName' => $job,
98-
'command' => $job,
99-
],
100-
];
101-
102-
return array_merge($payload, [
103-
'data' => [
10497
'commandName' => get_class($job),
10598
'command' => serialize(clone $job),
10699
],
107-
]);
100+
];
108101
}
109102

110103
public function getJobExpiration($job)

src/queue/Queueable.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,33 @@
1414
trait Queueable
1515
{
1616

17+
/** @var string 连接 */
18+
public $connection;
19+
1720
/** @var string 队列名称 */
1821
public $queue;
1922

2023
/** @var integer 延迟时间 */
2124
public $delay;
2225

26+
/**
27+
* 设置连接名
28+
* @param $connection
29+
* @return $this
30+
*/
31+
public function onConnection($connection)
32+
{
33+
$this->connection = $connection;
34+
35+
return $this;
36+
}
37+
2338
/**
2439
* 设置队列名
2540
* @param $queue
2641
* @return $this
2742
*/
28-
public function queue($queue)
43+
public function onQueue($queue)
2944
{
3045
$this->queue = $queue;
3146

0 commit comments

Comments
 (0)