11<?php
22namespace Barryvdh \Queue ;
33
4+ use Carbon \Carbon ;
5+ use DateTime ;
46use Illuminate \Database \Connection ;
57use Illuminate \Queue \DatabaseQueue ;
68use Illuminate \Queue \Jobs \DatabaseJob ;
@@ -45,7 +47,7 @@ public function __construct(Connection $database, $table, $default = 'default',
4547 public function push ($ job , $ data = '' , $ queue = null )
4648 {
4749 $ id = parent ::push ($ job , $ data , $ queue );
48- $ this ->startProcess ($ queue , $ id );
50+ $ this ->startProcess ($ id );
4951
5052 return $ id ;
5153 }
@@ -61,7 +63,7 @@ public function push($job, $data = '', $queue = null)
6163 public function pushRaw ($ payload , $ queue = null , array $ options = array ())
6264 {
6365 $ id = parent ::push ($ job , $ data , $ queue );
64- $ this ->startProcess ($ queue , $ id );
66+ $ this ->startProcess ($ id );
6567
6668 return $ id ;
6769 }
@@ -79,7 +81,7 @@ public function pushRaw($payload, $queue = null, array $options = array())
7981 public function later ($ delay , $ job , $ data = '' , $ queue = null )
8082 {
8183 $ id = parent ::later ($ delay , $ job , $ data , $ queue );
82- $ this ->startProcess ($ queue , $ id );
84+ $ this ->startProcess ($ id );
8385
8486 return $ id ;
8587 }
@@ -95,36 +97,46 @@ public function later($delay, $job, $data = '', $queue = null)
9597 public function release ($ queue , $ job , $ delay )
9698 {
9799 $ id = parent ::release ($ queue , $ job , $ delay );
98- $ this ->startProcess ($ queue , $ id );
100+ $ this ->startProcess ($ id );
99101
100102 return $ id ;
101103 }
102104
105+ protected function pushToDatabase ($ delay , $ queue , $ payload , $ attempts = 0 )
106+ {
107+ $ availableAt = $ delay instanceof DateTime ? $ delay : Carbon::now ()->addSeconds ($ delay );
108+
109+ return $ this ->database ->table ($ this ->table )->insertGetId ([
110+ 'queue ' => $ this ->getQueue ($ queue ),
111+ 'payload ' => $ payload ,
112+ 'attempts ' => $ attempts ,
113+ 'reserved ' => 1 ,
114+ 'reserved_at ' => $ this ->getTime (),
115+ 'available_at ' => $ availableAt ->getTimestamp (),
116+ 'created_at ' => $ this ->getTime (),
117+ ]);
118+ }
119+
103120 /**
104121 * Get the next available job for the queue.
105122 *
106123 * @param string|null $queue
107124 * @return \StdClass|null
108125 */
109- public function getJobFromId ($ queue , $ id )
126+ public function getJobFromId ($ id )
110127 {
111- $ this ->database ->beginTransaction ();
112128 $ job = $ this ->database ->table ($ this ->table )
113- ->lockForUpdate ()
114- ->where ('queue ' , $ this ->getQueue ($ queue ))
115- ->where ('reserved ' , 0 )
116129 ->where ('id ' , $ id )
117130 ->first ();
118131
119132 if ($ job ) {
120- $ this ->markJobAsReserved ($ job ->id );
121133
122134 return new DatabaseJob (
123- $ this ->container , $ this , $ job , $ queue
135+ $ this ->container , $ this , $ job , $ job -> queue
124136 );
125137 }
126138 }
127-
139+
128140 /**
129141 * Make a Process for the Artisan command for the job id.
130142 *
@@ -133,9 +145,9 @@ public function getJobFromId($queue, $id)
133145 *
134146 * @return void
135147 */
136- public function startProcess ($ queue , $ id )
148+ public function startProcess ($ id )
137149 {
138- $ command = $ this ->getCommand ($ queue , $ id );
150+ $ command = $ this ->getCommand ($ id );
139151 $ cwd = base_path ();
140152
141153 $ process = new Process ($ command , $ cwd );
@@ -150,16 +162,15 @@ public function startProcess($queue, $id)
150162 *
151163 * @return string
152164 */
153- protected function getCommand ($ queue , $ id )
165+ protected function getCommand ($ id )
154166 {
155167 $ connection = $ this ->connectionName ;
156- $ cmd = '%s artisan queue:async %d %s --env=%s --queue=%s ' ;
168+ $ cmd = '%s artisan queue:async %d %s ' ;
157169 $ cmd = $ this ->getBackgroundCommand ($ cmd );
158170
159171 $ binary = $ this ->getPhpBinary ();
160- $ environment = $ this ->container ->environment ();
161172
162- return sprintf ($ cmd , $ binary , $ id , $ connection, $ environment , $ this -> getQueue ( $ queue ) );
173+ return sprintf ($ cmd , $ binary , $ id , $ connection );
163174 }
164175
165176 /**
0 commit comments