1
1
<?php
2
2
namespace Barryvdh \Queue ;
3
3
4
- use Carbon \Carbon ;
5
- use DateTime ;
6
4
use Illuminate \Database \Connection ;
7
5
use Illuminate \Queue \DatabaseQueue ;
8
6
use Illuminate \Queue \Jobs \DatabaseJob ;
@@ -21,9 +19,9 @@ class AsyncQueue extends DatabaseQueue
21
19
22
20
/**
23
21
* @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
27
25
* @param string $binary
28
26
* @param string|array $binaryArgs
29
27
*/
@@ -53,20 +51,20 @@ public function push($job, $data = '', $queue = null)
53
51
}
54
52
55
53
/**
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 );
66
64
$ this ->startProcess ($ id );
67
65
68
66
return $ id ;
69
- }
67
+ }
70
68
71
69
/**
72
70
* Push a new job onto the queue after a delay.
@@ -86,40 +84,42 @@ public function later($delay, $job, $data = '', $queue = null)
86
84
return $ id ;
87
85
}
88
86
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
+ }
103
103
104
104
/**
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 ();
115
115
116
116
if ($ job ) {
117
117
118
- return new DatabaseJob (
119
- $ this ->container , $ this , $ job , $ job ->queue
120
- );
118
+ return new DatabaseJob (
119
+ $ this ->container , $ this , $ job , $ job ->queue
120
+ );
121
121
}
122
- }
122
+ }
123
123
124
124
/**
125
125
* Make a Process for the Artisan command for the job id.
0 commit comments