diff --git a/README.md b/README.md index 2772f4a..782e5ac 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ It requires **PHP >= 5.3.3** and **Nette Framework >= 2.0.0**. ## Usage -It is very simple to use it because configuration is only in method annotations. Example class follows: +It is very simple to use it because configuration is only in method annotations. Example class with tasks follows. ```php class CronTasks { @@ -38,24 +38,56 @@ class CronTasks { } ``` + It is recommend to use compiler extension. + +```neon +extension: + cronner: stekycz\Cronner\DI\CronnerExtension +``` + +It does not require any configuration however your own implementation of timestamp storage can be better +then the default. Your storage must be defined as a service in `config.neon` and Cronner will find it. However +you can specify service manually if it is not autowireable. + +```neon +cronner: + timestampStorage: @myCoolTimestampStorage +``` + +Or you can change the directory for default storage. + +```neon +cronner: + timestampStorage: stekycz\Cronner\TimestampStorage\FileStorage(%wwwDir%/../temp/cronner) +``` + +It is also possible to define `maxExecutionTime` for Cronner so you do not have make it by you own code +(and probably for all your requests). Option `criticalSectionTempDir` can be change however the directory +must be writable for php process. It is used to run each task only once at time. + +At the end you would need to specify your task objects. It would be some service with high probability. +You can add tag `cronner.tasks` to all services with Cronner tasks and those services will be bind +automatically. However you can still add new task objects by your own using `addTasks` method. + Then you can use it very easily in `Presenter` ```php class CronPresenter extends \Nette\Application\UI\Presenter { - private $cronner; - - public function injectCronner(Cronner $cronner) { - $this->cronner = $cronner; - } + /** + * @var \stekycz\Cronner\Cronner + * @inject + */ + public $cronner; public function actionCron() { - $this->cronner->addTasks(new CronTasks()); $this->cronner->run(); } } ``` -using service configuration + or in `Command` from [Kdyby/Console](https://github.com/Kdyby/Console). + +Service configuration is also possible but it should not be used using new versions of Nette. ```neon services: @@ -64,19 +96,6 @@ services: - addTasks(new CronTasks()) ``` -or using compiler extension - -```neon -cronner: - timestampStorage: stekycz\Cronner\TimestampStorage\FileStorage(%wwwDir%/../temp/cronner) -``` - -If you want to use Compiler Extension then do not forgot add following code to `bootstrap.php`. - -```php -stekycz\Cronner\DI\CronnerExtension::register($configurator); -``` - ## Annotations ### @cronner-task @@ -85,8 +104,10 @@ This annotations is **required for all** public methods which should be used as Its value is used as a name of task. If value is missing the name is build from class name and method name. -If this annotation is single (for Cronner) in task method comment then the task is runned -everytime when Cronner runs. +If this annotation is single (for Cronner) in task method comment then the task is run +every time when Cronner runs. + +**Note:** Magic methods cannot be used as task (`__construct`, `__sleep`, etc.). #### Example @@ -98,9 +119,9 @@ everytime when Cronner runs. ### @cronner-period -Not required but recomanded annotation which specifies period of task execution. +Not required but recommended annotation which specifies period of task execution. The period is minimal time between two executions of the task. It's value can be -anything what is acceptable for `strtotime()` method. +anything what is acceptable for `strtotime()` function. **Attention!** The value of this annotation must not contain any sign (+ or -). @@ -115,9 +136,9 @@ anything what is acceptable for `strtotime()` method. ### @cronner-days Allows run the task only on specified days. Possible values are abbreviations of week day names. -It means `Mon`, `Tue`, `Wed`, `Thu`, `Fri`, `Sat` and `Sun`. For simplier usage there are two shortcuts: -`working days` (`Mon`, `Tue`, `Wed`, `Thu`, `Fri`) and `weekend` (`Sat` and `Sun`) which are internaly -expanded to specific days. Multiple values must be separated by comma or can be specified by range `Mon-Thu`. +It means `Mon`, `Tue`, `Wed`, `Thu`, `Fri`, `Sat` and `Sun`. There are two shortcuts for easier usage: +`working days` (`Mon`, `Tue`, `Wed`, `Thu`, `Fri`) and `weekend` (`Sat` and `Sun`) which are internally +expanded to specific days. Multiple values must be separated by comma (`Mon, Wed, Fri`) or can be specified by range `Mon-Thu`. #### Example @@ -134,6 +155,9 @@ It uses 24 hour time model. Multiple values must be separated by comma. The time can be defined over midnight as it is in following example. +**Note:** There is tolerance time of 5 seconds to run task as soon as possible if previous run have had slower +start from any reason. + #### Example ```php @@ -171,4 +195,3 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/composer.json b/composer.json index 140dc55..f6a62ca 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "janmarek/mockista": "~1.0" }, "suggest": { - "kdyby/events": "Events for Nette Framework" + "kdyby/events": "Events for Nette Framework", + "kdyby/console": "Symfony Console integration for Kdyby components" }, "autoload": { "classmap": ["Cronner/"] diff --git a/tests/composer-nette-2.0.json b/tests/composer-nette-2.0.json index e8cec20..4696486 100644 --- a/tests/composer-nette-2.0.json +++ b/tests/composer-nette-2.0.json @@ -25,7 +25,8 @@ "janmarek/mockista": "~1.0" }, "suggest": { - "kdyby/events": "Events for Nette Framework" + "kdyby/events": "Events for Nette Framework", + "kdyby/console": "Symfony Console integration for Kdyby components" }, "autoload": { "classmap": ["Cronner/"] diff --git a/tests/composer-nette-2.1.json b/tests/composer-nette-2.1.json index f3d3067..c796665 100644 --- a/tests/composer-nette-2.1.json +++ b/tests/composer-nette-2.1.json @@ -25,7 +25,8 @@ "janmarek/mockista": "~1.0" }, "suggest": { - "kdyby/events": "Events for Nette Framework" + "kdyby/events": "Events for Nette Framework", + "kdyby/console": "Symfony Console integration for Kdyby components" }, "autoload": { "classmap": ["Cronner/"] diff --git a/tests/composer-nette-dev.json b/tests/composer-nette-dev.json index b8700e8..b039123 100644 --- a/tests/composer-nette-dev.json +++ b/tests/composer-nette-dev.json @@ -29,7 +29,8 @@ "janmarek/mockista": "~1.0" }, "suggest": { - "kdyby/events": "Events for Nette Framework" + "kdyby/events": "Events for Nette Framework", + "kdyby/console": "Symfony Console integration for Kdyby components" }, "autoload": { "classmap": ["Cronner/"]