File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,13 @@ namespace application\index\controller;
201201 * @param array|mixed $data 发布任务时自定义的数据
202202 */
203203 public function fire(Job $job,$data){
204-
204+ // 如有必要,可以根据业务需求和数据库中的最新数据,判断该任务是否仍有必要执行.
205+ $isJobStillNeedToBeDone = $this->checkDatabaseToSeeIfJobNeedToBeDone($data);
206+ if(!isJobStillNeedToBeDone){
207+ $job->delete();
208+ return;
209+ }
210+
205211 $isJobDone = $this->doHelloJob($data);
206212
207213 if ($isJobDone) {
@@ -219,6 +225,15 @@ namespace application\index\controller;
219225 }
220226 }
221227 }
228+
229+ /**
230+ * 有些消息在到达消费者时,可能已经不再需要执行了
231+ * @param array|mixed $data 发布任务时自定义的数据
232+ * @return boolean 任务执行的结果
233+ */
234+ private function checkDatabaseToSeeIfJobNeedToBeDone($data){
235+ return true;
236+ }
222237
223238 /**
224239 * 根据消息中的数据进行实际的业务处理
You can’t perform that action at this time.
0 commit comments