Services: Schedule code execution #40

Closed
opened 2014-10-14 22:26:56 +00:00 by jamie · 3 comments
jamie commented 2014-10-14 22:26:56 +00:00 (Migrated from git.hazaar.io)

This is a quick idea that I had to help make services a bit more useful.

Right now they can be used to either loop through the Service::run() method continuously or subscribe to events that execute a method when the event is triggered.

What I would like to do is add some functions that allow methods to be called at certain times.

For example, in the services init() method you could call something like:

$this->delay('myTestMethod', 60);

This will call the method only once in 60 seconds from now.

Or:

$this->schedule('myTestMethod', 'today 5pm');
$this->schedule('myTestMethod', 'next friday 2pm');

These will call the method at 5pm today then next friday at 2pm. This can use the \Hazaar\Date() object (and in turn the strtotime() function) to convert text to a date.

Or we can use the cron format, such as:

$this->cron('myTestMethod', '0 17 * * 1-5');

The method myTestMethod will execute at 5pm Mondays through Fridays.

This is a quick idea that I had to help make services a bit more useful. Right now they can be used to either loop through the _Service::run()_ method continuously or subscribe to events that execute a method when the event is triggered. What I would like to do is add some functions that allow methods to be called at certain times. For example, in the services _init()_ method you could call something like: ```php $this->delay('myTestMethod', 60); ``` This will call the method only once in 60 seconds from now. Or: ```php $this->schedule('myTestMethod', 'today 5pm'); $this->schedule('myTestMethod', 'next friday 2pm'); ``` These will call the method at 5pm today then next friday at 2pm. This can use the \Hazaar\Date() object (and in turn the _strtotime()_ function) to convert text to a date. Or we can use the cron format, such as: ```php $this->cron('myTestMethod', '0 17 * * 1-5'); ``` The method myTestMethod will execute at 5pm Mondays through Fridays.
jamie commented 2014-10-15 01:09:53 +00:00 (Migrated from git.hazaar.io)

Status changed to closed by commit 2b7edc

Status changed to closed by commit 2b7edc
jamie commented 2014-10-15 01:11:31 +00:00 (Migrated from git.hazaar.io)

mentioned in issue #28

mentioned in issue #28
jamie commented 2015-12-03 02:27:11 +00:00 (Migrated from git.hazaar.io)

mentioned in commit 2b7edcc4a9

mentioned in commit 2b7edcc4a95bb5286388b2985b0c11b5da2ba783
Commenting is not possible because the repository is archived.
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/hazaar-mvc-old#40
No description provided.