DQueueJob.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Module\LCache;
  3. use App\Module\DelayQueue\Redis;
  4. use UCore\Helper\Logger;
  5. abstract class DQueueJob implements QueueJobInterface,DQueueJobInterface
  6. {
  7. use QueueCache;
  8. static public function getDelay(): int
  9. {
  10. return 2;
  11. }
  12. /**
  13. * 事件监听
  14. * @param $user
  15. *
  16. */
  17. static public function eventListen($user)
  18. {
  19. $arg2 = [];
  20. $indexs = static::getRequiredArgIndex();
  21. foreach ($indexs as $index) {
  22. if (!isset($user->$index)) {
  23. Logger::error("Cache-error", [ $user, $indexs, $index ]);
  24. throw new \InvalidArgumentException("参数错误");
  25. }
  26. $arg2[$index] = $user->$index;
  27. }
  28. static::jobUpdate($arg2);
  29. }
  30. /**
  31. * 使用任务更新
  32. *
  33. * @param $arg
  34. * @return void
  35. */
  36. static protected function jobUpdate($parameter)
  37. {
  38. Redis::addQueue([static::class, 'updateSync'], $parameter, static::getDelay());
  39. }
  40. }