diff --git a/readme.md b/readme.md index f9bfb34..9a34316 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,10 @@ -# Laravel 5.3 Async Queue Driver +# Laravel 5.4 Async Queue Driver ## Push a function/closure to the background. + +### For Laravel 5.3, check the [0.5 branch](https://github.com/barryvdh/laravel-async-queue/tree/0.4) + Just like the 'sync' driver, this is not a real queue driver. It is always fired immediatly. The only difference is that the closure is sent to the background without waiting for the response. 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 ... 'async' => array( 'driver' => 'async', - 'table' => 'queue_jobs', + 'table' => 'jobs', 'queue' => 'default', 'expire' => 60, ), @@ -44,7 +47,7 @@ By default, `php` is used as the binary path to PHP. You can change this by addi ... 'async' => array( 'driver' => 'async', - 'table' => 'queue_jobs', + 'table' => 'jobs', 'queue' => 'default', 'expire' => 60, 'binary' => 'php', diff --git a/src/AsyncQueue.php b/src/AsyncQueue.php index 519aa5b..7525f1f 100644 --- a/src/AsyncQueue.php +++ b/src/AsyncQueue.php @@ -1,8 +1,6 @@ startProcess($id); return $id; - } + } /** * Push a new job onto the queue after a delay. @@ -86,40 +84,42 @@ public function later($delay, $job, $data = '', $queue = null) return $id; } - protected function pushToDatabase($delay, $queue, $payload, $attempts = 0) - { - $availableAt = $delay instanceof DateTime ? $delay : Carbon::now()->addSeconds($delay); - - return $this->database->table($this->table)->insertGetId([ - 'queue' => $this->getQueue($queue), - 'payload' => $payload, - 'attempts' => $attempts, - 'reserved' => 1, - 'reserved_at' => $this->getTime(), - 'available_at' => $availableAt->getTimestamp(), - 'created_at' => $this->getTime(), - ]); - } + /** + * Create an array to insert for the given job. + * + * @param string|null $queue + * @param string $payload + * @param int $availableAt + * @param int $attempts + * @return array + */ + protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0) + { + $record = parent::buildDatabaseRecord($queue, $payload, $availableAt, $attempts); + $record['reserved_at'] = $this->currentTime(); + + return $record; + } /** - * Get the next available job for the queue. - * - * @param string|null $queue - * @return \StdClass|null - */ - public function getJobFromId($id) - { - $job = $this->database->table($this->table) - ->where('id', $id) - ->first(); + * Get the next available job for the queue. + * + * @param string|null $queue + * @return \StdClass|null + */ + public function getJobFromId($id) + { + $job = $this->database->table($this->table) + ->where('id', $id) + ->first(); if($job) { - return new DatabaseJob( - $this->container, $this, $job, $job->queue - ); + return new DatabaseJob( + $this->container, $this, $job, $job->queue + ); } - } + } /** * Make a Process for the Artisan command for the job id.