-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some more information to readme.md
- Loading branch information
Fabrizio Branca
committed
Mar 6, 2015
1 parent
efd1808
commit 625a4c8
Showing
11 changed files
with
210 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
## Create a new job | ||
|
||
### Job implementation | ||
|
||
A job implementation is a simple callback. Your job class doesn't have to inherit from any specific class or implement any interface. You only need to create a model with a public method. Aoe_Scheduler will pass the current schedule object as a parameter in case you need to interact with it: | ||
|
||
```php | ||
class My_Module_Model_Job_Hello | ||
{ | ||
/** | ||
* Log 'Hello World' | ||
* | ||
* @param Aoe_Scheduler_Model_Schedule $schedule | ||
*/ | ||
public function run(/* Aoe_Scheduler_Model_Schedule $schedule */) | ||
{ | ||
Mage::log('Hello World'); | ||
} | ||
} | ||
|
||
``` | ||
|
||
### Register job in XML | ||
|
||
In your modules config.xml file (e.g. `app/code/local/My/Module/etc/config.xml`) add this snippet to let Magento know about the job you've created: | ||
|
||
```xml | ||
<config> | ||
<!-- ... --> | ||
<crontab> | ||
<jobs> | ||
<mymodule_helloworld> | ||
<schedule> | ||
<cron_expr>*/5 * * * *</cron_expr> | ||
</schedule> | ||
<run> | ||
<model>my_module/job_hello::run</model> | ||
</run> | ||
</mymodule_helloworld> | ||
</jobs> | ||
</crontab> | ||
<!-- ... --> | ||
</config> | ||
``` | ||
|
||
**Hint:** instead of hardcoding your schedule in '<schedule><cron_expr>' you can use '<schedule><config_path>' instead pointing to a configuration option that holds your schedule. This configuration option can be made avilable through 'System > Configuration'. | ||
On the other hand, Aoe Scheduler now let's you edit any job and overwrite any hardcoded schedule even if it wasn't pointing to a config path. | ||
|
||
TODO: Add complete list of xml tags here, with description (e.g. what's the run>model syntax...)! | ||
|
||
TODO: Add examples here of how to interact with Aoe_Scheduler through the $schedule object passed while calling the job. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## Heartbeat | ||
|
||
The heartbeat is a simple job that doesn't do anything except helping you to verify that your Magento instance is configured correctly. | ||
|
||
If everything is ok it will show a notice an all Aoe_Scheduler admin interfaces. If you're not seeing this message please check out the [instructions module](instructions.md) and fund some more information on how to [configure cron](cron-configuration.md) in this manual. | ||
|
||
 | ||
|
||
### Monitoring | ||
|
||
Sometimes - for various reasons - Magento's scheduler might stop working. Often there are business critical tasks that need to be run on a regular basis, so there's a need in monitoring the if everything works fine behind the scenes. That's why I added a new dummy job "Heartbeat". By default it runs every 5 minutes. This can be configured or even deactivated completely. This job does nothing but showing that the scheduler is working correctly. | ||
|
||
In addition to that there is a new shell command that allows you the check when a task was run successfully the last time (works for all scheduler job - not only for the heartbeat job): | ||
|
||
``` | ||
> php scheduler.php -action lastRun -code aoescheduler_heartbeat | ||
1327960203 | ||
``` | ||
|
||
By adding the "-secondsFromNow" parameter you'll get the duration since the last execution: | ||
|
||
``` | ||
> php scheduler.php -action lastRun -code aoescheduler_heartbeat -secondsFromNow | ||
35 | ||
``` | ||
|
||
So you can use this to integrate your instance to whatever monitoring you're using. Using the default configuration the last value must not be bigger than 5x60 = 300 seconds. If it is, there's something wrong with your scheduler. | ||
|
||
### Check any job | ||
|
||
If you have any other critical job you can check specifically check when this job ran as well: | ||
``` | ||
> php scheduler.php -action lastRun -code mymodule_helloworld | ||
1327960263 | ||
``` | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
## Web Services | ||
|
||
### Usage example | ||
|
||
1. Create a web service **user role**: | ||
Go to `System > Web Services -> Roles -> Role Resources` and set "Resource Access" to "all" or to "Custom" and select the specific options you want to grant to your web services user: | ||
 | ||
|
||
2. Create a web service user and assign him to the previously created role (`System > Web Services > Users`) | ||
|
||
3. Now you can access some scheduler functions (more might follow soon) via web service api. Currently only API v1 is implemented. | ||
|
||
|
||
```php | ||
<?php | ||
|
||
$client = new SoapClient('http://yourhost/api/?wsdl'); | ||
$session = $client->login('your_username', 'your_api_key'); | ||
|
||
// Run a scheduler task | ||
$result = $client->call($session, 'aoe_scheduler.runNow', array('aoecachecleaner')); | ||
var_dump($result); | ||
/* | ||
array(7) { | ||
["job_code"]=> | ||
string(15) "aoecachecleaner" | ||
["status"]=> | ||
string(7) "success" | ||
["created_at"]=> | ||
string(19) "2011-11-15 20:55:41" | ||
["scheduled_at"]=> | ||
string(19) "2011-11-15 20:55:41" | ||
["executed_at"]=> | ||
string(19) "2011-11-15 20:55:41" | ||
["finished_at"]=> | ||
string(19) "2011-11-15 20:55:41" | ||
["schedule_id"]=> | ||
string(6) "150006" | ||
} | ||
*/ | ||
|
||
// Schedule a task to run (from a normal scheduler process) as soon a possible ... | ||
$result = $client->call($session, 'aoe_scheduler.schedule', array('aoecachecleaner')); | ||
// ... or at a given time (e.g. in 1 hour): | ||
// $result = $client->call($session, 'aoe_scheduler.schedule', array('aoecachecleaner', time()+60*60)); | ||
var_dump($result); | ||
/* | ||
array(5) { | ||
["job_code"]=> | ||
string(15) "aoecachecleaner" | ||
["status"]=> | ||
string(7) "pending" | ||
["created_at"]=> | ||
string(19) "2011-11-15 21:06:07" | ||
["scheduled_at"]=> | ||
string(19) "2011-11-15 21:06:07" | ||
["schedule_id"]=> | ||
string(6) "150007" | ||
} | ||
*/ | ||
|
||
// Get information on an existing task | ||
$result = $client->call($session, 'aoe_scheduler.info', array('150007')); | ||
var_dump($result); | ||
/* | ||
array(5) { | ||
["job_code"]=> | ||
string(15) "aoecachecleaner" | ||
["status"]=> | ||
string(7) "pending" | ||
["created_at"]=> | ||
string(19) "2011-11-15 21:06:07" | ||
["scheduled_at"]=> | ||
string(19) "2011-11-15 21:06:07" | ||
["schedule_id"]=> | ||
string(6) "150007" | ||
} | ||
*/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters