0

i am using postgresql as db, in .env i have set QUEUE_CONNECTION = database

I download from url, for example, a picture and transfer it to the queue for uploading in storage laravel

In web.php, I registered a route to the queue

Route::get('/job', function () {
    App\Jobs\FileAdd::dispatch("https://www.example.com/example.jpg")->delay(now()->addMinute(25));
});

In job, I wrote the following:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;


class FileAdd implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $File;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($File)
    {
        $this->File = $File;


    }

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

        info($data = $this->File);

        $pos = strripos($data, '/');

        $link = substr($data, 0 , $pos+1);
        $filename = substr($data, $pos+1);
        $expansion = substr($filename, -4);
        $tempImageTwink = tempnam('..\storage\app\public', $filename);
        $tempImage = substr($tempImageTwink, 0, -4) . $expansion;
        copy($link . '/' . $filename, $tempImage);
        Storage::delete('exa3BBD.tmp');
        response()->download($tempImage, $filename);
        unlink(($tempImageTwink ));
    }
}

in the database I have two tables jobs, failed_jobs, for writing queues, but they are executed immediately without delay, what could be the problem?

  • Try this in delay method as `delay(Carbon::now()->addMinutes(25))` – Hassan Malik Apr 06 '21 at 12:28
  • He is already doing so, `now()` is an alias for `Carbon::now()`, you also have `today()` as `Carbon::today()`... – matiaslauriti Apr 06 '21 at 12:40
  • Does this answer your question? [Laravel queued jobs processed immediately even with a delay](https://stackoverflow.com/questions/31091535/laravel-queued-jobs-processed-immediately-even-with-a-delay) – matiaslauriti Apr 06 '21 at 12:41

1 Answers1

-2

Might be problem with cache if you just change it in .env file. Laravel cache your .env file and look at the cache if it is available not the .env file itself. So changes is not active, unless you will clear you cache or create new one. Try clear your cache with:

php artisan optimize:clear

or

php artisan cache:clear

so new data from .env file can be loaded.

James
  • 214
  • 1
  • 8