Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 411d6e3

Browse files
crlcubarryvdh
authored andcommitted
Make it compatible with Laravel 5.4 (barryvdh#65)
1 parent 9fa7673 commit 411d6e3

File tree

2 files changed

+50
-47
lines changed

2 files changed

+50
-47
lines changed

readme.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
# Laravel 5.3 Async Queue Driver
1+
# Laravel 5.4 Async Queue Driver
22

33
## Push a function/closure to the background.
44

5+
6+
### For Laravel 5.3, check the [0.5 branch](https://github.com/barryvdh/laravel-async-queue/tree/0.4)
7+
58
Just like the 'sync' driver, this is not a real queue driver. It is always fired immediatly.
69
The only difference is that the closure is sent to the background without waiting for the response.
710
This package is more usable as an alternative for running incidental tasks in the background, without setting up a 'real' queue driver.
@@ -31,7 +34,7 @@ You should now be able to use the async driver in config/queue.php. Use the same
3134
...
3235
'async' => array(
3336
'driver' => 'async',
34-
'table' => 'queue_jobs',
37+
'table' => 'jobs',
3538
'queue' => 'default',
3639
'expire' => 60,
3740
),
@@ -44,7 +47,7 @@ By default, `php` is used as the binary path to PHP. You can change this by addi
4447
...
4548
'async' => array(
4649
'driver' => 'async',
47-
'table' => 'queue_jobs',
50+
'table' => 'jobs',
4851
'queue' => 'default',
4952
'expire' => 60,
5053
'binary' => 'php',

src/AsyncQueue.php

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
namespace Barryvdh\Queue;
33

4-
use Carbon\Carbon;
5-
use DateTime;
64
use Illuminate\Database\Connection;
75
use Illuminate\Queue\DatabaseQueue;
86
use Illuminate\Queue\Jobs\DatabaseJob;
@@ -21,9 +19,9 @@ class AsyncQueue extends DatabaseQueue
2119

2220
/**
2321
* @param \Illuminate\Database\Connection $database
24-
* @param string $table
25-
* @param string $default
26-
* @param int $expire
22+
* @param string $table
23+
* @param string $default
24+
* @param int $expire
2725
* @param string $binary
2826
* @param string|array $binaryArgs
2927
*/
@@ -53,20 +51,20 @@ public function push($job, $data = '', $queue = null)
5351
}
5452

5553
/**
56-
* Push a raw payload onto the queue.
57-
*
58-
* @param string $payload
59-
* @param string $queue
60-
* @param array $options
61-
* @return mixed
62-
*/
63-
public function pushRaw($payload, $queue = null, array $options = array())
64-
{
65-
$id = parent::pushRaw($payload, $queue, $options);
54+
* Push a raw payload onto the queue.
55+
*
56+
* @param string $payload
57+
* @param string $queue
58+
* @param array $options
59+
* @return mixed
60+
*/
61+
public function pushRaw($payload, $queue = null, array $options = array())
62+
{
63+
$id = parent::pushRaw($payload, $queue, $options);
6664
$this->startProcess($id);
6765

6866
return $id;
69-
}
67+
}
7068

7169
/**
7270
* Push a new job onto the queue after a delay.
@@ -86,40 +84,42 @@ public function later($delay, $job, $data = '', $queue = null)
8684
return $id;
8785
}
8886

89-
protected function pushToDatabase($delay, $queue, $payload, $attempts = 0)
90-
{
91-
$availableAt = $delay instanceof DateTime ? $delay : Carbon::now()->addSeconds($delay);
92-
93-
return $this->database->table($this->table)->insertGetId([
94-
'queue' => $this->getQueue($queue),
95-
'payload' => $payload,
96-
'attempts' => $attempts,
97-
'reserved' => 1,
98-
'reserved_at' => $this->getTime(),
99-
'available_at' => $availableAt->getTimestamp(),
100-
'created_at' => $this->getTime(),
101-
]);
102-
}
87+
/**
88+
* Create an array to insert for the given job.
89+
*
90+
* @param string|null $queue
91+
* @param string $payload
92+
* @param int $availableAt
93+
* @param int $attempts
94+
* @return array
95+
*/
96+
protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0)
97+
{
98+
$record = parent::buildDatabaseRecord($queue, $payload, $availableAt, $attempts);
99+
$record['reserved_at'] = $this->currentTime();
100+
101+
return $record;
102+
}
103103

104104
/**
105-
* Get the next available job for the queue.
106-
*
107-
* @param string|null $queue
108-
* @return \StdClass|null
109-
*/
110-
public function getJobFromId($id)
111-
{
112-
$job = $this->database->table($this->table)
113-
->where('id', $id)
114-
->first();
105+
* Get the next available job for the queue.
106+
*
107+
* @param string|null $queue
108+
* @return \StdClass|null
109+
*/
110+
public function getJobFromId($id)
111+
{
112+
$job = $this->database->table($this->table)
113+
->where('id', $id)
114+
->first();
115115

116116
if($job) {
117117

118-
return new DatabaseJob(
119-
$this->container, $this, $job, $job->queue
120-
);
118+
return new DatabaseJob(
119+
$this->container, $this, $job, $job->queue
120+
);
121121
}
122-
}
122+
}
123123

124124
/**
125125
* Make a Process for the Artisan command for the job id.

0 commit comments

Comments
 (0)