@@ -20,13 +20,11 @@ class AsyncJob extends SyncJob
2020 *
2121 * @param \Illuminate\Container\Container $container
2222 * @param \Barryvdh\Queue\Models\Job $job
23- *
24- * @return void
2523 */
2624 public function __construct (Container $ container , Job $ job )
2725 {
28- $ this ->job = $ job ;
2926 $ this ->container = $ container ;
27+ $ this ->job = $ job ;
3028 }
3129
3230 /**
@@ -37,7 +35,7 @@ public function __construct(Container $container, Job $job)
3735 public function fire ()
3836 {
3937 // Get the payload from the job
40- $ payload = $ this ->parsePayload ($ this ->job -> payload );
38+ $ payload = $ this ->parsePayload ($ this ->getRawBody () );
4139
4240 // If we have to wait, sleep until our time has come
4341 if ($ this ->job ->delay ) {
@@ -60,6 +58,48 @@ public function fire()
6058 }
6159 }
6260
61+ /**
62+ * Get the raw body string for the job.
63+ *
64+ * @return string
65+ */
66+ public function getRawBody ()
67+ {
68+ return $ this ->job ->payload ;
69+ }
70+
71+ /**
72+ * Release the job back into the queue.
73+ *
74+ * @param int $delay
75+ * @return void
76+ */
77+ public function release ($ delay = 0 )
78+ {
79+ // Update the Job status
80+ $ this ->job ->status = Job::STATUS_OPEN ;
81+ $ this ->job ->retries ++;
82+ $ this ->job ->save ();
83+
84+ // Wait for the delay
85+ if ($ delay ) {
86+ sleep ($ this ->getSeconds ($ delay ));
87+ }
88+
89+ // Fire again
90+ $ this ->fire ();
91+ }
92+
93+ /**
94+ * Get the number of times the job has been attempted.
95+ *
96+ * @return int
97+ */
98+ public function attempts ()
99+ {
100+ return (int ) $ this ->job ->retries + 1 ;
101+ }
102+
63103 /**
64104 * Delete the job from the queue.
65105 *
@@ -82,4 +122,14 @@ protected function parsePayload($payload)
82122 {
83123 return json_decode ($ payload , true );
84124 }
125+
126+ /**
127+ * Get the job identifier.
128+ *
129+ * @return string
130+ */
131+ public function getJobId ()
132+ {
133+ return $ this ->job ->id ;
134+ }
85135}
0 commit comments