Messenger.php 875 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\job;
  3. use think\queue\Job;
  4. use think\facade\Log;
  5. /**
  6. * Description of Messenger
  7. *
  8. * @author sgq
  9. */
  10. class Messenger {
  11. public function fire(Job $job, $data) {
  12. if ($this->deal($data)) {
  13. Log::record(json_encode($data));
  14. $job->delete();
  15. return true;
  16. }
  17. Log::error(json_encode($data));
  18. if ($job->attempts() >= 3) {
  19. $job->delete();
  20. return false;
  21. }
  22. $job->release(10); //10秒后重试
  23. }
  24. /**
  25. * 处理业务逻辑
  26. * @param type $data
  27. * @return bool
  28. */
  29. public function deal($data): bool {
  30. $type = $data["type"];
  31. switch ($data) {
  32. case 1:
  33. //通知单位审核注册
  34. break;
  35. case 2:
  36. break;
  37. }
  38. return false;
  39. }
  40. }