I have set up tasks on kernel.php. I have set up a similar debian environment locally, and the tasks are running as expected. However, on the server, tasks are not running if withoutOverlapping() method is given. If withoutOverlapping() is not given, tasks are running as expected.
Current configuration on kernel.php
$schedule->command('perform:task_one')->withoutOverlapping()->everyFiveMinutes();
Task is not fired at all. If I remove withoutOverlapping, task is fired.
I have implemented withoutOverlapping as my task involves some mailing and may consume time at instances.
Related
In this moment i have a shared hosting server.
In my app i want to use Laravel's queue system, but i can't maintain the command php artisan queue:work beacuse i can't install a supervisor.
With a little bit of an effort, i can move my app on a VPS, but i don't have much of experience with servers and i'm a little scared that my app will be offline much time.
Considering lack of experience on server side, i have this questions:
Is it ok to use Laravel queues with cron jobs? Can it break in any way?
Only for this problem should i upgrade to an VPS or i should remain on this shared hosting server ( i have ssh access here )?
Quick answer: you should not use Laravel queues without a process monitor such as Supervisor.
It all depends of what you want to achieve, but an alternative to queues would be using the laravel scheduler: you can trigger the scheduler with a cron task (every minute for example), and dispatch jobs easily.
And if you really want to use the queues, a solution could be to add your jobs to the queue, and process them using a cron task every minute running the following command: php artisan queue:work. But I would recommend the previous solution.
After running the command:
php artisan queue:work
Expected behaviour: that the queue worker will continue to run until stopped or it fails.
Actual behaviour: queue worker stops after every job, regardless if the job fails or completes successfully.
The above is consistent with Laravel 5.2
https://laravel.com/docs/5.2/queues#daemon-queue-worker
However, since I am running Laravel 5.7 I would expect the behaviour described in
https://laravel.com/docs/5.7/queues#running-the-queue-worker
When running a worker in Laravel forge the queue worker seems to restart after every job.
Are there any configurations that I am missing that would explain this behaviour?
NOTE: when the queue worker ends there are no exceptions thrown and
nothing logged. it simply restarts.
You are right, php artisan queue:work should run until stopped manually. The only exceptions are the following options:
--once Only process the next job on the queue
--stop-when-empty Stop when the queue is empty
My guess would be that Laravel forge uses supervisor which restarts background jobs every so often to prevent memory leaks and other failures. For more information about supervisor in laravel see the docs.
Have you tried running it in your development environment to see if it restarts there as well?
I am going to create Task Shedule in laravel 5.6 in my app. I am working with windows 7 os and my localhost is WAMP. in laravel documentation there is add Cron entries to your server as
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
but I have not any idea about how to add Cron entries with My wamp localhost. my laravel file is in the desktop name as schoolproject then how can add Cron entries with my wamp?
For people who run a local WAMP server and their computer isn't always awake
I spent the past couple months figuring out what would work best.
First, set up your Kernel class and console commands as instructed in the Laravel docs.
In Windows, open Task Scheduler, and create a new task:
In the Triggers section, you can set it like this:
The action should be to run the PHP executable within your WAMP folder (using artisan schedule:run) as the argument:
But then here is an important difference from other tutorials I've seen:
For any tasks that are critical, you'll want to treat them separately.
For example, let's assume you have a task that backs up your database, and you'd like to run this every single day at noon, so your Kernel class has this command in its schedule.
But then you realize a flaw in this approach: if you were out at lunch a few days in a row and left your computer asleep, that noon task would have been missed, and now your backups would be quite stale.
So, remove that daily database backups command from the schedule in Kernel, and instead, then create a second task within Windows Task Scheduler, and set the trigger like:
Then in its Settings tab, you can choose "Run task as soon as possible after a scheduled start is missed":
Therefore, even if your computer is off or asleep at this task's scheduled time, Windows will know to run the task immediately upon waking.
I want to implement a queue for sending out emails in Laravel. I have the queue working fine, but am worried about efficiency. These are my settings:
I have created the jobs table and set up the .env file, to use the queues with my local database.
I have set up this crontab on the server:
* * * * * php /var/www/imagine.dev/artisan schedule:run >> /dev/null 2>&1
And have set up a schedule in app\Conosle\Kernel.php, so I dont have to manually enter the 'queue:listen' every time through console.
$schedule->command('queue:listen');
Now to my question. I would like to know if this is efficient? I am worried about having the queue:listen running all the time in the background consuming cpu and memory.
I have been trying to only run the queue:listen once every 5 minutes, and then put it to sleep with
$schedule->command('queue:listen --sleep 300');
but again, am not sure if this is the best approach.
Another thing I tried is using 'queue:work', but this only processes one queue at a time.
Ideally, I would like a way, to process all the queues every 5 minutes, avoiding a constant use of memory and cpu.
What is the best approach?
Not sure which version of Laravel you're using, but I suspect it's 5.2 or earlier.
You do not need to run this every minute, it continues to run until it's manually stopped.
From Laravel 5.2 documentation:
Note that once this task has started, it will continue to run until it is manually stopped. You may use a process monitor such as Supervisor to ensure that the queue listener does not stop running.
So maybe you want to look into Supervisor
Also, if this is helpful at all, you can chain onto $schedule, ->everyFiveMinutes(). There are several other methods available as well. Laravel Scheduling
I working currently on a simple Reminder Laravel app for Heroku. I've written my API and everything works well. Now I want to run a scheduled task on Heroku.
Basically I'm looking for something to execute the following command on a separate dyno:
php EmailScheduler.php
or
php artisan schedule:emails
This command should be a long running process where e.g. each minute the same task is being executed over and over.
In this task I want to query my database and get all reminders that are due and send them as an email so I have to be able to access the business logic of my application like eloquent models.
I know about the scheduler add-on or about certain "cron" solutions but I would like a PHP only solution so just a long running script or task that might sleep most of the time and wake up each minute or so.
In Ruby (Rails) for example I could require the environment, thereby have access to my business logic and then fire up a timer task using the concurrent-ruby library.
I already tried to require the
bootstrap/autoload.php
bootstrap/app.php
files but it seems like I have to do more than just this, like boot the application.
How can I solve this using the Laravel framework and possibly other third-party libraries ?
Task Scheduling in laravel is done by making a cron job. By defining a cron job, one can schedule a task to be excuted at a defind period.
You follow the official documentation of laravel for scheduling: https://laravel.com/docs/5.3/scheduling
In 2017, you indeed couldn't use cron on Heroku. As of 2021, you can use Cron To Go, an Heroku add-on, to set up a cron job that runs on one-off dynos in Heroku. Simply follow the guide here to run Laravel's scheduler once a minute.