How can i set custom retry_after for long running jobs | laravel

joy

Question: How to customize long-running job without attempting multiple time after each retry_after seconds?

I have one job which will take 1 to 3 hours to run, I already created job-based on laravel documentation, here is my job file.

<?php


namespace App\Modules\Csv\Jobs;

use App\Jobs\Job;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use League\Csv\Reader;
use Phone;

/**
 * A single excel import job, which can be pushed on to a queue
 */
class UploadCsvDataInTable extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels, Dispatchable,Queueable;

    public $timeout = 172800;
    /**
     * The excel to import
     *
     * @var App\BulkUpload
     */
    protected $csvUpload;

    /**
     * Create a new job instance.
     *
     * @param App\FeedImport
     *
     * @return void
     */
    public function __construct(CsvUpload $csvUpload)
    {
        $this->csvUpload = $csvUpload;
    }

    public function handle()
    {

        app(CsvUploadService::class)->uploadCsv($this->csvUpload);

    }
}

here is Laravel document to specify a timeout for jobs.

here is code for how I am calling that job.

UploadCsvDataInTable::dispatch($csvUpload)->onConnection('redis')->onQueue('low');

my command for queue:work In supervisor.

php artisan queue:work --queue=high,low,default --sleep=3 --tries=3

here is my configuration for queue & horizon

// horizon.php
 'production' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue'      => ['high', 'default', 'low'],
                'balance'    => 'simple',
                'processes'  => 6,
                'tries'      => 3,
            ],
 ],

  //queue.php

  'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => env('REDIS_QUEUE', 'default'),
            'retry_after' => 90,
            'block_for' => null,
        ],

I can see because of retry_after my job is attempting multiple time and after reaching 3 try as per horizon configuration its throwing MaxAttemptsExceededException.

if I increase $timeout to 24 hours I am getting duplicate records in my db as retry_after is attempting that job multiple time.

is there any way I can set custom retry_after for this job?

joy

I have created another connection for long-running jobs and its working properly for me.

created new supervisor connection in horizon.php for long running process

'supervisor-long-running' => [
                'connection' => 'redis-long-processes',
                'queue' => 'long-running',
                'balance' => 'simple',
                'processes' => 3,
                'tries' => 1,
                'timeout' => 86000 // should be shorter than retry_after out
]

and new redis connection in queue.php

 'redis-long-processes' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => 'long-running',
            'retry_after' => 86400,
            'block_for' => null,
        ],

in database.php added new queue for long running jobs.

'queue' => [
                [
                    'connection' => 'redis',
                    'queue'      => ['high', 'default', 'low','long-running'],
                    'balance'    => 'simple',
                    'processes'  => 6,
                    'tries'      => 3,
                    'url' => env('REDIS_URL'),
                    'host' => env('REDIS_HOST', '127.0.0.1'),
                    'password' => env('REDIS_PASSWORD', null),
                    'port' => env('REDIS_PORT', '6379'),
                    'database' => env('REDIS_CACHE_DB', '1'),
                ],
            ],

also don't forgot to call jobs using onConnection and onQueue to specify from which queue jobs should execute.

UploadDataInTable::dispatch($upload)->onConnection('redis-long-processes')->onQueue('long-running');

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Laravel 5.5 - How can I add a custom value to Auth::user() after successfully login

分類Dev

How can I set up Celery to call a custom worker initialization?

分類Dev

How can i set icon on custom plugin in wordpress

分類Dev

How can I use my custom class in a view on Laravel 5

分類Dev

How can I get a list of long running processes that match a particular pattern?

分類Dev

How do I kill zombie/phantom scheduler jobs in laravel forge?

分類Dev

How can I delete all xprint jobs for one printer?

分類Dev

How can I custom rename podcasts after downloading them with gPodder?

分類Dev

How can I add a custom fee in woocommerce that is calculated after tax

分類Dev

How set timeout for jobs in sidekiq

分類Dev

Custom keyboard shortcuts are reset. How can I make them set permanently?

分類Dev

How can I know whether a JobScheduler is running?

分類Dev

How can I see what processes are running?

分類Dev

Laravel Queued Jobs Running for Many Minutes Longer Than Timeout

分類Dev

How can i make this custom Stepper?

分類Dev

how can I make a custom overlay filter?

分類Dev

How Can I Create A Custom Property Type

分類Dev

How can I force running a php extension after each php call without explicitly writing the code?

分類Dev

How can I keep a python script on a remote server running after closing out of SSH?

分類Dev

How can I tell which user limit I am running into?

分類Dev

How can I create a procedure from a long command in R?

分類Dev

How can I add comments in long docker RUN commands?

分類Dev

How can I break only long words in IE?

分類Dev

How can I find an IP address in a long string with REGEX

分類Dev

Rails 4: How can I decouple logic in this long controller method?

分類Dev

How can i convert the string to a set in python

分類Dev

How can I set class name dynamically?

分類Dev

How can I set Timezone in lumen 5.2?

分類Dev

how can i set a link in website to button

Related 関連記事

  1. 1

    Laravel 5.5 - How can I add a custom value to Auth::user() after successfully login

  2. 2

    How can I set up Celery to call a custom worker initialization?

  3. 3

    How can i set icon on custom plugin in wordpress

  4. 4

    How can I use my custom class in a view on Laravel 5

  5. 5

    How can I get a list of long running processes that match a particular pattern?

  6. 6

    How do I kill zombie/phantom scheduler jobs in laravel forge?

  7. 7

    How can I delete all xprint jobs for one printer?

  8. 8

    How can I custom rename podcasts after downloading them with gPodder?

  9. 9

    How can I add a custom fee in woocommerce that is calculated after tax

  10. 10

    How set timeout for jobs in sidekiq

  11. 11

    Custom keyboard shortcuts are reset. How can I make them set permanently?

  12. 12

    How can I know whether a JobScheduler is running?

  13. 13

    How can I see what processes are running?

  14. 14

    Laravel Queued Jobs Running for Many Minutes Longer Than Timeout

  15. 15

    How can i make this custom Stepper?

  16. 16

    how can I make a custom overlay filter?

  17. 17

    How Can I Create A Custom Property Type

  18. 18

    How can I force running a php extension after each php call without explicitly writing the code?

  19. 19

    How can I keep a python script on a remote server running after closing out of SSH?

  20. 20

    How can I tell which user limit I am running into?

  21. 21

    How can I create a procedure from a long command in R?

  22. 22

    How can I add comments in long docker RUN commands?

  23. 23

    How can I break only long words in IE?

  24. 24

    How can I find an IP address in a long string with REGEX

  25. 25

    Rails 4: How can I decouple logic in this long controller method?

  26. 26

    How can i convert the string to a set in python

  27. 27

    How can I set class name dynamically?

  28. 28

    How can I set Timezone in lumen 5.2?

  29. 29

    how can i set a link in website to button

ホットタグ

アーカイブ