11<?php
22namespace Barryvdh \Queue ;
33
4- use Carbon \Carbon ;
5- use DateTime ;
64use Illuminate \Database \Connection ;
75use Illuminate \Queue \DatabaseQueue ;
86use 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