Skip to content

Commit

Permalink
Merge pull request #29 from stekycz/feature/v1.0.0
Browse files Browse the repository at this point in the history
Version 1.0.0 release preparation
  • Loading branch information
stekycz committed Aug 17, 2014
2 parents 07219a1 + 9079913 commit 2134e94
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 33 deletions.
81 changes: 52 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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 -).

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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.

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"]
Expand Down
3 changes: 2 additions & 1 deletion tests/composer-nette-2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"]
Expand Down
3 changes: 2 additions & 1 deletion tests/composer-nette-2.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"]
Expand Down
3 changes: 2 additions & 1 deletion tests/composer-nette-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"]
Expand Down

0 comments on commit 2134e94

Please sign in to comment.