merianos's avatar

Can I run queue jobs manually without run artisan queue:listen?

Hello,

First of all, I like to apologize for the following question if this seems to be weird.

I am totally new on Lumen, and I just build the DB tables ( jobs, failed_jobs ) required for the queues.

Also, I built the following job that does nothing impressive ( at least not yet ):

<?php

namespace App\Jobs;

class InsertEvents extends Job {
    public function __construct() {}

    public function handle() {}
}

In addition, in my controller class I have entered the following code in order to insert the new jobs in the jobs table:

$job = ( new InsertEvents( 'Job Body' ) )->onQueue( 'events' );
dispatch( $job );

Until now, the work is done very nice. I run my controller action and I insert the jobs in the jobs table.

Now, what I like to ask, is if it's possible to run the Job Workers manually without using the artisan queue:listen.

The reason I am asking for that is because I don't know a lot from server management, and thus I am not able to run the command on my clients' server. Yes, I know it seems to be very simple the configuration, but I not aware of debugging the server in case that something goes wrong with it and that's why I am looking to avoid it.

In addition, locally, I have run both the php artisan queue:work and the php artisan queue:listen & but I didn't see any changes in my jobs table. What supposed to happen once I run the commands? Should the records removed one by one from the DB because it should get processed by the Worker?

Finally, when I mean if there's a way to run the jobs manually, I mean to install a CRON Jobs on my clients' server to execute a call in a given URL of the app, and the controller responsible for this URL to execute the next job in the queue.

Kind regards Merianos Nikos

0 likes
3 replies
EventFellows's avatar

Yes, once the queue worker runs jobs should disappear from the jobs table as they get processed (if there are errors they might end up on the failed jobs table).

have you set your queue driver in .env file to database?

And to your question in the title: you can set the .env to 'sync' so jobs are processed synchronously (but be aware they are directly processed, they are not put on the jobs table at any point)

2 likes
merianos's avatar

Hello @EventFellows,

thanks for your answer. Yes, I have set the database in the .env file like this QUEUE_DRIVER=database.

What means the jobs are processed synchronously? And how are they processed? Should I install a cron job to some controller? What is the process for this kind of setup?

In addition, in this case, the jobs where are they stored? When I use the database setting in the .env, the jobs are stored in the jobs table. In the sync option, where are they stored?

Thank in advance!

EventFellows's avatar
Level 16

they are not stored anywhere they are immediately processed. if you put your setting to sync you do not need any cron service.

2 likes

Please or to participate in this conversation.