LiveRoomSendTask.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Task;
  4. use App\Master\Framework\Extend\BaseTask;
  5. use App\Model\Arts\LiveRoomModel;
  6. use App\Service\QueueService;
  7. use App\Utils\LogUtil;
  8. use Hyperf\Crontab\Annotation\Crontab;
  9. use Hyperf\Di\Annotation\Inject;
  10. #[Crontab(rule: "*\/10 * * * * *", name: "LiveRoomSendTask", callback: "execute", memo: "直播间数据推送 每3秒执行一次", enable: true)]
  11. class LiveRoomSendTask extends BaseTask {
  12. //日志板块
  13. protected string $LOG_MODULE = 'LiveRoomSendTask';
  14. #[Inject]
  15. protected QueueService $service;
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. }
  20. public function do(): bool
  21. {
  22. // 查询正在直播的房间 推入到数据更新队列
  23. $model = new LiveRoomModel();
  24. $list = $model->getList(['status' => 1]);
  25. if (!empty($list)){
  26. foreach ($list as $item){
  27. // 加入点赞队列
  28. $this->service->liveRoomSendPush([
  29. 'room_no' => $item['room_no']
  30. ]);
  31. }
  32. }
  33. return $this->success('执行成功');
  34. }
  35. }