123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace app\admin\queue;
- use app\admin\service\QueueService;
- use think\console\Output;
- class JobsQueue
- {
-
- const STATUS_PEND = 1;
-
- const STATUS_PROC = 2;
-
- const STATUS_COMP = 3;
-
- const STATUS_FAIL = 4;
-
- protected $id;
-
- protected $data;
-
- protected $title;
-
- protected $status;
-
- protected $output;
-
- protected $statusDesc = '';
-
- public function fire(\think\queue\Job $job, $data = [])
- {
- $this->data = $data;
- $this->output = new Output();
- $this->id = isset($data['_job_id_']) ? $data['_job_id_'] : '';
- $this->title = isset($data['_job_title_']) ? $data['_job_title_'] : '';
- $this->output->newLine();
- $this->output->writeln(" system task {$this->id} execution start");
- $this->output->writeln('---------------------------------------------');
- QueueService::status($this->id, self::STATUS_PROC, $this->statusDesc);
- if ($this->execute()) {
- $this->output->writeln('---------------------------------------------');
- $this->output->info(" successful");
- $this->status = self::STATUS_COMP;
- } else {
- $this->output->writeln('---------------------------------------------');
- $this->output->error(" failure");
- $this->status = self::STATUS_FAIL;
- }
- $job->delete();
- QueueService::status($this->id, $this->status, $this->statusDesc);
- $this->output->writeln('---------------------------------------------');
- $this->output->newLine();
- }
-
- protected function execute()
- {
- return true;
- }
- }
|