archiveExpiredStories(); $this->rotateMedia(); } protected function archiveExpiredStories() { $stories = Story::whereActive(true) ->where('expires_at', '<', now()) ->get(); foreach($stories as $story) { StoryExpire::dispatch($story)->onQueue('story'); } } protected function rotateMedia() { $queue = StoryService::rotateQueue(); if(!$queue || count($queue) == 0) { return; } collect($queue) ->each(function($id) { $story = StoryService::getById($id); if(!$story) { StoryService::removeRotateQueue($id); return; } if($story->created_at->gt(now()->subMinutes(20))) { return; } StoryRotateMedia::dispatch($story)->onQueue('story'); StoryService::removeRotateQueue($id); }); } }