due() ->each(function (Post $post) { // Atomically claim the post — only dispatch if we successfully change its status $claimed = Post::where('id', $post->id) ->where('status', PostStatus::Scheduled) ->update(['status' => PostStatus::Publishing]); if ($claimed) { PublishPost::dispatch($post); } }); } }