Scheduling Tasks in an Addon
Created 7 years ago by failcookieI have a task that needs to run on a daily basis (3am at night). It's all tied to a specific addon. It's a pretty simple task - at 3am, it will call a job that will parse through files and upload documents. In Laravel, I would jump into the Console/Kernel and add a $schedule->daily
to the list. How do I go about this same process in Pyro?
Perfect! I saw you posted daily
- does it support similar options as the Laravel task scheduling? (https://laravel.com/docs/5.4/scheduling#schedule-frequency-options)
I'm more specifically looking at certain times of the day to run like dailyAt('3:00')
EDIT: What do I put in the class file to make sure it gets called? I did something like this just to make sure it was working, but I am guessing that is not proper.
public function getName()
{
dd(true);
}
I just had the same problem. After review the implementation I could find out how to define more complicated frequencies. Here are some examples:
/**
* The addon's scheduled commands.
*
* @type array|null
*/
protected $schedules = [
'dailyAt|11:00' => [ImportCarList::class], // dailyAt('13:00')
'twiceDaily|1, 13' => [ImportCarList::class] // twiceDaily(1, 13)
];
You can define them in
config/streams.php
but it's pry best to do them in your addon service provider (doc was missing - just added): https://pyrocms.com/documentation/streams-platform/latest#core-concepts/service-providers/writing-service-providers/addonserviceprovider-schedules