-
app/Jobs/ProcessTipsJob.php
Open in GitHubuse App\Types\Job; use App\Models\Tip; use Illuminate\Database\Eloquent\Collection; class ProcessTipsJob extends Job { protected array $fields = [ 'tips.id', 'tips.user_id', 'tips.slug', 'tips.summary', 'tips.first_tag', ]; public int $tries = 1; public function handle() : void { Tip::query() ->select($this->fields) ->join('users', 'tips.user_id', '=', 'users.id') ->where('shared', false) ->whereBetween('published_at', [now()->subDay(), now()]) ->chunkById(50, fn($tips) => $this->process($tips)); } public function process(Collection $tips) : void { $query = Tip::whereIn('id', $tips->pluck('id')); attempt(fn() => $query->update(['shared' => true])); $tips->each(fn($tip) => PostToSocialMediaJob::dispatch($tip)); } }
-
app/Commands/ProcessTipsCommand.php
Open in GitHubuse App\Jobs\ProcessTipsJob; use Illuminate\Console\Command; class ProcessTipsCommand extends Command { protected $signature = 'system:process-tips'; protected $description = 'Publish scheduled tips and notify followers.'; public function handle() : void { ProcessTipsJob::dispatch(); $this->info('The tips are being processed'); } }