Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Enable batch jobs delay for database queue #41758

Merged

Conversation

civilcoder55
Copy link
Contributor

[before]

  • batch jobs was ignoring delay time when inserting into database.

[after]

  • batch jobs delay time will be considered and stored into database.
use App\Jobs\ImportCsv;
use Illuminate\Bus\Batch;
use Illuminate\Support\Facades\Bus;
 
$batch = Bus::batch([
    (new ImportCsv(1, 100))->delay($delay),
    (new ImportCsv(101, 200))->delay($delay)
])->dispatch();

civilcoder55 and others added 2 commits March 31, 2022 07:25
[before]
- batch jobs was ignoring delay time when inserting into database.

[after]
- batch jobs delay time will be considered and stored into database.
@taylorotwell taylorotwell merged commit 60115bd into laravel:9.x Mar 31, 2022
@GrahamCampbell GrahamCampbell changed the title enable batch jobs delay for database queue ⏰ [9.x] Enable batch jobs delay for database queue ⏰ Mar 31, 2022
@GrahamCampbell GrahamCampbell changed the title [9.x] Enable batch jobs delay for database queue ⏰ [9.x] Enable batch jobs delay for database queue Mar 31, 2022
@georanma
Copy link

georanma commented Apr 5, 2022

@civilcoder55 thanks for this update. Does this work with setting the delay in the job constructor as well? I've no been able to bump to Laravel 9 yet, but this will be a nice improvement.

@civilcoder55
Copy link
Contributor Author

@civilcoder55 thanks for this update. Does this work with setting the delay in the job constructor as well? I've no been able to bump to Laravel 9 yet, but this will be a nice improvement.

Hi, @georanma
sorry for the delay in replying!

if you mean delay in the job constructor like this, yes you can do it

<?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 SampleJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $data;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(array $data)
    {
        $this->data = $data;
        $this->delay(now()->addMinute(1));
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
    }
}

@georanma
Copy link

georanma commented Apr 8, 2022

@civilcoder55 awesome. Thank you again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants