Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid overriding of Event::$omitErrors value while running commands #63

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c523b55
Avoid overriding of Event::$omitErrors value while running
lexeo May 17, 2020
9bdff03
Detach fork. Update namespaces, package name & author, fix typos, etc.
lexeo May 19, 2020
517b9f5
Reformat code using PSR-12
lexeo May 19, 2020
bbc3d28
Bugfix. Remove symfony/process 4.* constraint (actually not supported)
lexeo May 19, 2020
cc28e8c
Bugfix. Allow setting timezone as a string as well as DateTimeZone obj
lexeo May 19, 2020
44d81e4
Bugfix. Set correct expression format. Update frequency methods
lexeo May 19, 2020
3ad4e59
Refactor Event. Extract common code into AbstractEvent class
lexeo May 19, 2020
c079b02
Refactor Event. Make Mutex optional (only for preventing overlapping)
lexeo May 20, 2020
e4bbabe
Remove useless references to Application object
lexeo May 20, 2020
85c8ed9
Refactor Event. Allow changing working directory
lexeo May 20, 2020
0881086
More flexible configuration of run conditions using when/skip methods
lexeo May 20, 2020
3132420
Bugfix. Allow running CLI commands in background
lexeo May 22, 2020
32c8a9f
Fix. Schedule::dueEvents() should filter events only by cron expression
lexeo May 22, 2020
f3f3d69
Fix. Set the initial cwd for process instead of using cd command
lexeo May 22, 2020
5b8c8aa
Fix. Use absolute path to Yii CLI entry point to be able to change cwd
lexeo May 22, 2020
33f5562
Fix. Ensure jobs can be run without overlapping
lexeo May 22, 2020
f5b22e3
Rename Event -> Job. Test classes
lexeo May 22, 2020
8c46509
Rename Event -> Job. General classes
lexeo May 22, 2020
8ba90f1
Rename Event -> Job. Methods, props & vars
lexeo May 22, 2020
3bd96bc
Fix (minor). Controller run/finish actions
lexeo May 22, 2020
fc6df02
Fix. CallbackJob::run() catch exceptions thrown in callback
lexeo May 23, 2020
44842d0
Add tests for CallbackJob
lexeo May 23, 2020
c5b251a
Add all supported PHP versions 5.4-7.1 to TravisCI config
lexeo May 23, 2020
c4ef396
Prefer stable composer packages by default
lexeo May 23, 2020
c3e0f71
Return the support of Symfony/Process v4
lexeo May 23, 2020
b6d51d5
Add PHPUnit v5 to allow running tests on PHP 7.1
lexeo May 24, 2020
3dd9053
Disable autoRelease for the FileMutex used by default
lexeo May 24, 2020
a50ab0c
Make CallbackJob::$result protected, add getter for retrieving a value
lexeo May 24, 2020
bfab8c1
Remove useless 'config' param from Job constructors
lexeo May 24, 2020
7b5b502
Drop the support of pinging a URL after finishing a job
lexeo May 24, 2020
eb4dca0
Create mutexName for CallbackJob based on serialized callable and params
lexeo May 24, 2020
dc9cfbc
Move the timezone setting from a Job to the Schedule
lexeo May 24, 2020
eae5309
Make Schedule responsible for preventing job overlapping (Mutex aware)
lexeo May 24, 2020
d039b7a
Give a proper name for the method that returns a unique Job identifier
lexeo May 24, 2020
ef0c5c4
Remove prefix from Job ID. Allow to set a mutex key prefix in Schedule
lexeo May 24, 2020
fdc7136
Allow force running concurrent shell jobs in background
lexeo May 24, 2020
bbbe225
Add support of dry run
lexeo May 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
language: php

os: linux
dist: trusty

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1

env:
global:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2015 Pavel Agalecky <pavel.agalecky@gmail.com>
Copyright (c) 2020 Aleksei Grishatkin <lexeodev@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
62 changes: 27 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Schedule extension for Yii2
===========================
Job scheduling extension for Yii2
=================================

This extension is the port of Laravel's Schedule component (https://laravel.com/docs/master/scheduling#scheduling-artisan-commands)
This extension inspired by Laravel's [Console\Scheduling](https://laravel.com/docs/master/scheduling) component
and based on the [omnilight/yii2-scheduling](https://github.com/omnilight/yii2-scheduling)
but intended to fix a number of found bugs in the last and provide a really working solution.

Installation
------------
Expand All @@ -11,21 +13,21 @@ The preferred way to install this extension is through [composer](http://getcomp
Either run

```
php composer.phar require omnilight/yii2-scheduling "*"
php composer.phar require lexeo/yii2-scheduling "*"
```

or add

```json
"omnilight/yii2-scheduling": "*"
"lexeo/yii2-scheduling": "*"
```

to the `require` section of your composer.json.

Description
-----------

This project is inspired by the Laravel's Schedule component and tries to bring it's simplicity to the Yii framework.
This project inspired by the Laravel's Scheduling component and tries to bring its simplicity to the Yii framework.
Quote from Laravel's documentation:

```
Expand All @@ -46,15 +48,13 @@ application
Schedule examples
-----------------

This extension is support all features of Laravel's Schedule, except environments and maintance mode.
This extension supports most of the features of Laravel's Scheduling, except environments and maintenance mode.

**Scheduling Closures**

```php
$schedule->call(function()
{
$schedule->call(function() {
// Do some task...

})->hourly();
```

Expand Down Expand Up @@ -134,8 +134,7 @@ $schedule->command('foo')->sundays();
**Only Allow Job To Run When Callback Is True**

```php
$schedule->command('foo')->monthly()->when(function()
{
$schedule->command('foo')->monthly()->when(function() {
return true;
});
```
Expand All @@ -151,7 +150,7 @@ $schedule->command('foo')->sendOutputTo($filePath)->emailOutputTo('[email protected]
```php
$schedule->command('foo')->withoutOverlapping();
```
Used by default yii\mutex\FileMutex or 'mutex' application component (http://www.yiiframework.com/doc-2.0/yii-mutex-mutex.html)
Used by default [yii\mutex\FileMutex](https://www.yiiframework.com/doc/api/2.0/yii-mutex-filemutex) or 'mutex' application component if defined.

**Running Tasks On One Server**

Expand Down Expand Up @@ -182,13 +181,13 @@ $schedule->command('report:generate')
How to use this extension in your application?
----------------------------------------------

You should create the following file under `@console/config/schedule.php` (note: you can create file with any name
and extension and anywere on your server, simpli ajust the name of the scheduleFile in the command below):
You should create the following file under `@console/config/schedule.php` (note: you can create a file with any name
and extension and anywhere on your server, simply adjust the name of the scheduleFile in the command below):

```php
<?php
/**
* @var \omnilight\scheduling\Schedule $schedule
* @var \lexeo\yii2scheduling\Schedule $schedule
*/

// Place here all of your cron jobs
Expand All @@ -200,33 +199,33 @@ $schedule->exec('ls')->everyFiveMinutes();
$schedule->command('migrate')->hourly();

// This command will call callback function every day at 10:00
$schedule->call(function(\yii\console\Application $app) {
$schedule->call(function() {
// Some code here...
})->dailyAt('10:00');

```

Next your should add the following command to your crontab:
Next you should add the following command to your crontab:
```
* * * * * php /path/to/yii yii schedule/run --scheduleFile=@console/config/schedule.php 1>> /dev/null 2>&1
```

That's all! Now all your cronjobs will be runned as configured in your schedule.php file.
That's all! Now all your cron jobs will be run as configured in your schedule.php file.

How to use this extension in your own extension?
------------------------------------------------

First of all, you should include dependency to the `omnilight\yii2-scheduling` into your composer.json:
First of all, you should include dependency to the `lexeo\yii2-scheduling` into your composer.json:

```
...
'require': {
"omnilight/yii2-schedule": "*"
"lexeo/yii2-schedule": "*"
}
...
```

Next you should create bootstrapping class for your extension, as described in the http://www.yiiframework.com/doc-2.0/guide-structure-extensions.html#bootstrapping-classes
Next you should create bootstrapping class for your extension, [as described in the documentation](http://www.yiiframework.com/doc-2.0/guide-structure-extensions.html#bootstrapping-classes)

Place into your bootstrapping method the following code:

Expand All @@ -235,9 +234,9 @@ public function bootstrap(Application $app)
{
if ($app instanceof \yii\console\Application) {
if ($app->has('schedule')) {
/** @var omnilight\scheduling\Schedule $schedule */
/** @var lexeo\yii2scheduling\Schedule $schedule */
$schedule = $app->get('schedule');
// Place all your shedule command below
// Place all your schedule command below
$schedule->command('my-extension-command')->dailyAt('12:00');
}
}
Expand All @@ -250,22 +249,15 @@ and add `schedule/run` command to the crontab as described upper.
Using `schedule` component
--------------------------

You do not have to use `schedule` component directly or define it in your application if you use schedule only in your application (and do not want to give ability for extensions to register they own cron jobs). But if you what to give extensions ability to register cronjobs, you should define `schedule` component in the application config:
You do not have to use `schedule` component directly or define it in your application if you use schedule only in your application (and do not want to give ability for extensions to register they own cron jobs).
But if you what to give extensions ability to register cron jobs, you should define `schedule` component in the application config:

```php
'schedule' => 'omnilight\scheduling\Schedule',
```

Using addition functions
------------------------

If you want to use `thenPing` method of the Event, you should add the following string to the `composer.json` of your app:
```
"guzzlehttp/guzzle": "~5.0"
'schedule' => 'lexeo\yii2scheduling\Schedule',
```

Note about timezones
--------------------

Please note, that this is PHP extension, so it use timezone defined in php config or in your Yii's configuration file,
Please note, that this is PHP extension, so it uses the timezone defined in php config or in your Yii's configuration file,
so set them correctly.
21 changes: 12 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "omnilight/yii2-scheduling",
"name": "lexeo/yii2-scheduling",
"description": "Scheduling extension for Yii2 framework",
"keywords": [
"yii",
"scheduling",
"cron"
],
"minimum-stability": "dev",
"prefer-stable": true,
"authors": [
{
"name": "Pavel Agalecky",
"email": "pavel.agalecky@gmail.com"
"name": "Aleksei Grishatkin",
"email": "lexeodev@gmail.com"
}
],
"type": "yii2-extension",
Expand All @@ -21,18 +22,20 @@
"dragonmantank/cron-expression": "1.*"
},
"require-dev": {
"phpunit/phpunit": "4.8.36"
},
"suggest": {
"guzzlehttp/guzzle": "Required to use the thenPing method on schedules (~5.0)."
"phpunit/phpunit": "4.8.36 || 5.*"
},
"autoload": {
"psr-4": {
"omnilight\\scheduling\\": "src"
"lexeo\\yii2scheduling\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"lexeo\\yii2scheduling\\tests\\": "tests/"
}
},
"extra": {
"bootstrap": "omnilight\\scheduling\\Bootstrap"
"bootstrap": "lexeo\\yii2scheduling\\Bootstrap"
},
"scripts": {
"test": "vendor/bin/phpunit"
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
verbose="true"
>
<testsuites>
<testsuite name="omnilight/yii2-scheduling test suite">
<testsuite name="lexeo/yii2-scheduling test suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
Expand Down
Loading