findChapterLives(); echo sprintf('pending lives: %s', $chapterLives->count()) . PHP_EOL; if ($chapterLives->count() == 0) return; echo '------ start close live task ------' . PHP_EOL; foreach ($chapterLives as $chapterLive) { $chapterLive->status = ChapterLiveModel::STATUS_INACTIVE; $chapterLive->update(); $chapterRepo = new ChapterRepo(); $chapter = $chapterRepo->findById($chapterLive->chapter_id); $attrs = $chapter->attrs; $attrs['stream']['status'] = ChapterModel::SS_INACTIVE; $chapter->attrs = $attrs; $chapter->update(); $cache = new CourseChapterListCache(); $cache->rebuild($chapterLive->course_id); } echo '------ end close live task ------' . PHP_EOL; } /** * 查找待关闭直播 * * @param int $limit * @return ResultsetInterface|Resultset|ChapterLiveModel[] */ protected function findChapterLives(int $limit = 100) { $status = ChapterLiveModel::STATUS_ACTIVE; $endTime = time() - 3600; return ChapterLiveModel::query() ->where('status = :status:', ['status' => $status]) ->andWhere('end_time < :end_time:', ['end_time' => $endTime]) ->limit($limit) ->execute(); } }