Laravel 5.5 Job with delay fires instantly instead of waiting - php

In my application I am dispatching a job on work queue with delay time. But its work instantly not waiting for delay time. In my config and eve I am using driver as database.
In my database job table not insert any job till now.
My config:
'default' => env('QUEUE_DRIVER', 'database')
My controller code:
Log::info('Request Status Check with Queues Begins', __METHOD__);
MyGetInfo::dispatch($this->name,$this->password,$this->id,$trr->id)->onQueue('work')->delay(12);
return json_encode($data);

The value of QUEUE_DRIVER must be set to database in .env file.
make sure to run this afterwards:
php artisan config:clear
also run
php artisan queue:listen

Related

Laravel Queue - Database in cache?

I have an application with multiple databases;
I have a function to "choose" the correct database;
The problem is: when I start php artisan queue:work --tries=3
The project join in MySqlConnector.php only in first time.
So, I just can connect in my correct database in the first time.
Attempts fails
Disconnect \DB::disconnect('database name'),
Clear cache \Cache::flush();
Change the mysql default config(['database.connections.queue' => $correctDatabase]);
And several others I don't even remember anymore.
How do I make sure that whenever I enter a queue worker, I will connect back to the database?
Note: I enter the correct database configuration inside MySQLConnector in the connect method.
public function connect(array $config)
{
// ...
// multipleDatabases is my custom function
if(multipleDatabases('connection') !== null) {
$config = multipleDatabases('database');
}
// ...
}
This code working fine.
I solve this problem using listen instead of worker
php artisan queue:listen --tries=3
Laravel documentation
When using the queue:listen command, you don't have to manually restart the worker after your code is changed; however, this command is not as efficient as queue:work:

Laravel dispatch job run async

I have a function that posts some content and pushes a job onto a queue and returns response to user even before the queue complete the job.
for that I changed the .env QUEUE_DRIVER to database, And records is saved in table jobs, but to execute this jobs I have to call the command php artisan queue:work, and that is my question: how do I call this command in the code or what should I do whenever there is jobs in the table?
The command
php artisan:queue work
Should be runnig always it will check if there is new jobs he will dispatch them
But it should be always running you can't execute it from the code
Also you can run
php artisan queue:work --tries=5
This for example will try 5 times then it will stop
Plus you can install supervisor it will always start the queue:work if it faild

Cron jobs on shared hosting using laravel scheduler not working

I am having issue of running laravel scheduler to send mails in the queue
The setup is as follows: Laravel 5.7
I have configured the scheduler (App/Console/Kernel.php) like mentioned below
protected function schedule(Schedule $schedule)
{
$schedule->command('queue:work --tries=3')->everyFiveMinutes()->withoutOverlapping();
}
The db is set-up as per laravel docs. As soon as I click the link in my UI, I can see the entry in the db.
The .env QUEUE_CONNECTION=database and the same setting in Config/queue.php
(if i change the database to sync, it works perfectly)
My cron job in the server is as follows ( i just tried to log the cron)
/usr/local/bin/php /home/XXX/YYY/artisan schedule:run 1>> /home/XXX/public_html/junk/cron_log.php 2>&1
I can see the cron logs getting updated every five minues but
"No scheduled commands are ready to run"
Exactly the same code and settings last night worked(before going to bed). I had tested for more than
40 emais send attempts and the db entries were getting deleted. I only tried to save the scheduler with everyFiveMinues() but now it is not working.
I can understand mails reaching slowly but why the db entries were not deleted like last night?
this may be useful to other who are using Laravel 5.7, shared hosting Godaddy.
The above issue of dispatching email jobs was not executing ( I mean the cron jobs are running but database entries are not cleared. The issue seems to be with
->withoutOverlapping();
After I have deleted this method, I am now seeing the cron_log entries correctly and I have also received mails. My cron_log entries are as seen below
Running scheduled command: '/opt/alt/php71/usr/bin/php' 'artisan' queue:work --tries=3 > '/dev/null' 2>&1
I am guessing the method withoutOverlapping() has problem in cron execution. I have not changed anything in the code.

Laravel queues, how come the queue is processed right away?

Hello I've setup queues with Laravel 5.1.
I perform the HTTP request (Post), this is routed to the respective controller.
Controller executes the following:
//try saving model
try{
$lg = new User();
$lg->fill($request);
$lg->save();
}catch(QueryException $e){
Log::error( $e->getCode());
}
//creates Job instance
$job = new ProcessUser($lg);
//dispatching job
$queue_id = $this->dispatch($job);
also if I
dump($queue_id);
instead of having the Id key fo the queue I get back 0.
Everything works.....as expected on local dev env, with Homestead.
But on production where I have CentOS...
I expected the job just to be queued. Instead seems like it 's processed right away. (I can never see the Job inserted in my queue)
On my server (CentOS 6) I installed supervisor.
And it is stopped:
$ service supervisord status
supervisord is stopped
And also... I hardly doubt It could work since I didn't configure it in
/etc/supervisor.conf
What am I missing?
How can I check out how's processed the queue?
I have never issued any artisan command like
$php artisan queue:*
Sorry all,
I realised I didn't configured properly the .env file by setting
QUEUE_DRIVER=database
it was set to
QUEUE_DRIVER=sync
Didn't know that "sync" config would process right away the queue...

What would prevent jobs in a queue from processing? [PHP / Laravel 5]

I have a queue I set up in Laravel 5 to delete companies and associated records. Each time this happens, a lot of work happens on the back-end, so queues are my best option.
I set up my config/queue.php file along with my .env file so that the database driver will be used. I am using the Queue::pushOn method to push jobs onto a queue called company_deletions. Ex.
Queue::pushOn('company_deletions', new CompanyDelete($id));
Where CompanyDelete is a command created with php artisan command:make CompanyDelete --queued
I have tried to get my queue to process using the following commands:
php artisan queue:work
php artisan queue:work company_deletions
php artisan queue:listen
php artisan queue:listen company_deletions
php artisan queue:work database
php artisan queue:listen database
Sometimes when looking at the output of the above commands, I get the following error:
[InvalidArgumentException]
No connector for []
Even when I don't get an error I cannot get it to actually process the jobs for some reason. When I look in my jobs table, I can see the job on the queue, however the attempts column shows 0, reserved shows 0 and reserved_at is null. Am I missing some steps? I have looked over the documentation several times and cannot for the life of me figure out what is wrong. I don't see anything in the laravel error logs either. What would prevent these jobs from being processed once they are in the jobs database? Any help is appreciated.
i run into a smiliar issue because i dont add the jobs in the default queue..
$job = (new EmailJob(
$this->a,
$this->b,
$this->c,
$this->d,
$e
))->onQueue('emails');
then i have to listen to the specific queue:
php artisan queue:listen --queue=emails
in your case it would be
php artisan queue:listen --queue=company_deletions

Categories