s24WebDev's avatar

Delaying Jobs

Hey guys i want to delaying a job within my Controller. I migrated the jobs table on my sqlite connection and configured the queue driver to database. But no job was stored in the database. what am i doing wrong?

env

DB_CONNECTION=sqlite
QUEUE_DRIVER=database

queue conf

'database' => [
            'driver' => 'database',
            'connection' => 'sqlite',
            'table' => 'jobs',
            'queue' => 'default',
            'retry_after' => 90,
        ],

Controller

public function rotate()
    {
        OrderAndRegisterCerts::dispatch()->delay(Carbon::now()->addMinutes(3));
        return DomainHandler::rotate();
    }

Job

<?php

namespace App\Jobs;

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

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

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $a = 1+2;
        echo $a;
    }
}
0 likes
14 replies
s24WebDev's avatar

Yes i executed the migrations and the table is there but always empty The table is named jobs

bashy's avatar

Is your timezone correct? What does Carbon::now()->addMinutes(3)

s24WebDev's avatar

The carbon line gives me the following:

Carbon {#267
  +"date": "2017-09-08 11:04:11.313592"
  +"timezone_type": 3
  +"timezone": "UTC"
}```
bashy's avatar

And that's correct for your time?

s24WebDev's avatar

no my time is 2 hours later. i will try to set my timezone correctly

s24WebDev's avatar

Okay, the Timezone is now correct but this does not did the trick. the db table is still empty :(

bashy's avatar

@tarik In config/app.php there's a setting which is for timezone

'timezone' => 'Europe/London',
1 like
bashy's avatar
bashy
Best Answer
Level 65

@webcodecs Yeah I guess it should still insert it even if it's 2hrs later. I've not used the database queue before. Have you tested with Redis?

s24WebDev's avatar

I will test it with redis today and will give my feedback

s24WebDev's avatar

@bashy With redis its working fine. It does not solve the problem but working with redis is more fun anyway ;)

bashy's avatar

@webcodecs Good stuff. Redis always works and it's easy to install. Just make sure that you name your queue in config/queue.php if you have multiple apps running on Redis.

s24WebDev's avatar

@bashy for now i only have one queue. But thanks for the tip! thread closed

Please or to participate in this conversation.