stackkit/laravel-google-cloud-tasks-queue

How to respect the order FIFO cloud tasks

azizimohamed opened this issue · 1 comments

I have just question if I want the order to be respected first in first out in cloud tasks what should I do is this possible?

I think this is not possible

Screenshot 2023-02-11 at 13 19 23

A possible way to achieve this is by using job batching. However that only works if you already know before hand which jobs to execute.
I think you will have to simulate a FIFO queue by storing the jobs somewhere and manually execute them in order:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class FifoJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function handle()
    {
        foreach (StoredJobs::latest()->limit(50)->lazy() as $job) {
            $this->execute($job);
        }
    }
}

dispatch(new FifoJob()); // process first 50 in order
dispatch(new FifoJob()); // process next 50 in order
dispatch(new FifoJob()); // etc...