Skip to content

Commit

Permalink
Merge pull request #8 from kbond/refactor
Browse files Browse the repository at this point in the history
Refactor to remove concept of self running tasks and self handling extensions
  • Loading branch information
kbond authored May 7, 2020
2 parents 991d640 + acc35af commit 76636e5
Show file tree
Hide file tree
Showing 75 changed files with 1,944 additions and 1,915 deletions.
106 changes: 45 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Task Scheduling feature](https://laravel.com/docs/master/scheduling).
1. [Installation](#installation)
2. [Quick Start](#quick-start)
3. [Defining the Schedule](doc/define-schedule.md)
1. [Bundle Configuration](doc/define-schedule.md#bundle-configuration)
2. [ScheduleBuilder Service](doc/define-schedule.md#schedulebuilder-service)
3. [Self-Scheduling Commands](doc/define-schedule.md#self-scheduling-commands)
4. [Your Kernel](doc/define-schedule.md#your-kernel)
1. [ScheduleBuilder Service](doc/define-schedule.md#schedulebuilder-service)
2. [Your Kernel](doc/define-schedule.md#your-kernel)
3. [Bundle Configuration](doc/define-schedule.md#bundle-configuration)
4. [Self-Scheduling Commands](doc/define-schedule.md#self-scheduling-commands)
5. [Timezone](doc/define-schedule.md#timezone)
6. [Schedule Extensions](doc/define-schedule.md#schedule-extensions)
1. [Filters](doc/define-schedule.md#filters)
Expand All @@ -35,8 +35,8 @@ Task Scheduling feature](https://laravel.com/docs/master/scheduling).
1. [CommandTask](doc/define-tasks.md#commandtask)
2. [CallbackTask](doc/define-tasks.md#callbacktask)
3. [ProcessTask](doc/define-tasks.md#processtask)
3. [PingTask](doc/define-tasks.md#pingtask)
4. [CompoundTask](doc/define-tasks.md#compoundtask)
5. [NullTask](doc/define-tasks.md#nulltask)
2. [Task Description](doc/define-tasks.md#task-description)
3. [Frequency](doc/define-tasks.md#frequency)
1. [Cron Expression](doc/define-tasks.md#cron-expression)
Expand Down Expand Up @@ -70,59 +70,40 @@ Task Scheduling feature](https://laravel.com/docs/master/scheduling).

## Installation

### Applications that use Symfony Flex

```console
$ composer require zenstruck/schedule-bundle
```

### Applications that don't use Symfony Flex

1. Download the Bundle

```console
$ composer require zenstruck/schedule-bundle
```

2. Enable the Bundle

```php
// config/bundles.php
return [
// ...
Zenstruck\ScheduleBundle\ZenstruckScheduleBundle::class => ['all' => true],
];
```
*If not using Symfony Flex, be sure to enable the bundle.*

## Quick Start

1. Add tasks and schedule configuration to your bundle config:

```yaml
# config/packages/zenstruck_schedule.yaml

zenstruck_schedule:
email_handler: # enable email notifications
default_from: [email protected]
default_to: [email protected]

timezone: America/New_York # all tasks will run in this timezone
1. Add your schedule service (assumes *autowire* and *autoconfiguration* enabled):

schedule_extensions:
environiments: prod # only run when in production
email_on_failure: ~ # send email if some tasks fail

tasks:
- task: app:send-weekly-report
frequency: '0 * * * 0' # Sundays @ 1am
email_on_failure: ~ # send email if this task fails
ping_on_success: https://www.example.com/weekly-report-healthcheck
- task: app:send-hourly-report [email protected] [email protected]
frequency: '0 9-17 * * 1-5' # Hourly on weekdays between 9am and 5pm
without_overlapping: ~ # prevent running over itself
ping_on_success: https://www.example.com/hourly-report-healthcheck
```php
// src/Schedule/AppScheduleBuilder.php

use Zenstruck\ScheduleBundle\Schedule;
use Zenstruck\ScheduleBundle\Schedule\ScheduleBuilder;

class AppScheduleBuilder implements ScheduleBuilder
{
public function buildSchedule(Schedule $schedule): void
{
$schedule
->timezone('UTC')
->environments('prod')
;

$schedule->addCommand('app:send-weekly-report --detailed')
->description('Send the weekly report to users.')
->sundays()
->at(1)
;

// ...
}
}
```

2. List your tasks to diagnose any problems:
Expand All @@ -137,24 +118,27 @@ $ composer require zenstruck/schedule-bundle
* * * * * cd /path-to-your-project && bin/console schedule:run >> /dev/null 2>&1
```

See [Defining the Schedule](doc/define-schedule.md) and [Defining Tasks](doc/define-tasks.md)
for more options.

## Full Configuration Reference

```yaml
zenstruck_schedule:

# The LockFactory service to use
without_overlapping_handler: null # Example: lock.default.factory
# The LockFactory service to use for the without overlapping extension
without_overlapping_lock_factory: null # Example: lock.default.factory

# The LockFactory service to use - be sure to use a "remote store" (https://symfony.com/doc/current/components/lock.html#remote-stores)
single_server_handler: null # Example: lock.redis.factory
# The LockFactory service to use for the single server extension - be sure to use a "remote store" (https://symfony.com/doc/current/components/lock.html#remote-stores)
single_server_lock_factory: null # Example: lock.redis.factory

# The HttpClient service to use
ping_handler: null # Example: http_client
http_client: null # Example: http_client

# The default timezone for tasks (override at task level), null for system default
timezone: null # Example: America/New_York

email_handler:
mailer:
enabled: false

# The mailer service to use
Expand Down Expand Up @@ -185,7 +169,7 @@ zenstruck_schedule:
email_on_failure:
enabled: false

# Email address to send email to (leave blank to use "zenstruck_schedule.email_handler.default_to")
# Email address to send email to (leave blank to use "zenstruck_schedule.mailer.default_to")
to: null

# Email subject (leave blank to use extension default)
Expand Down Expand Up @@ -257,8 +241,8 @@ zenstruck_schedule:
# Prototype
-

# Defaults to CommandTask, prefix with "bash:" to create ProcessTask, pass (null) to create NullTask, pass array of commands to create CompoundTask (optionally keyed by description)
task: ~ # Required, Example: "my:command arg1 --option1=value" or "bash:/bin/my-script"
# Defaults to CommandTask, prefix with "bash:" to create ProcessTask, prefix url with "ping:" to create PingTask, pass array of commands to create CompoundTask (optionally keyed by description)
task: ~ # Required, Example: "my:command arg1 --option1=value", "bash:/bin/my-script" or "ping:https://example.com"

# Cron expression
frequency: ~ # Required, Example: '0 * * * *'
Expand Down Expand Up @@ -344,7 +328,7 @@ zenstruck_schedule:
email_after:
enabled: false

# Email address to send email to (leave blank to use "zenstruck_schedule.email_handler.default_to")
# Email address to send email to (leave blank to use "zenstruck_schedule.mailer.default_to")
to: null

# Email subject (leave blank to use extension default)
Expand All @@ -354,7 +338,7 @@ zenstruck_schedule:
email_on_failure:
enabled: false

# Email address to send email to (leave blank to use "zenstruck_schedule.email_handler.default_to")
# Email address to send email to (leave blank to use "zenstruck_schedule.mailer.default_to")
to: null

# Email subject (leave blank to use extension default)
Expand Down
12 changes: 6 additions & 6 deletions doc/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $ bin/console schedule:list
[WARNING] 1 task issue:
[ERROR] To use the email extension you must configure a mailer (config path: "zenstruck_schedule.email_handler").
[ERROR] To use the email extension you must configure a mailer (config path: "zenstruck_schedule.mailer").
! [NOTE] For more details, run php bin/console schedule:list --detail
Expand All @@ -74,7 +74,7 @@ $ bin/console schedule:list
[WARNING] 1 issue with schedule:
[ERROR] To use "onSingleServer" you must configure a lock factory (config path:
"zenstruck_schedule.single_server_handler").
"zenstruck_schedule.single_server_lock_factory").
```

![schedule:list with issues](images/schedule-list-with-issues.png)
Expand Down Expand Up @@ -105,7 +105,7 @@ $ bin/console schedule:list --detail
[WARNING] 1 issue with this task:
[ERROR] To use the email extension you must configure a mailer (config path: "zenstruck_schedule.email_handler").
[ERROR] To use the email extension you must configure a mailer (config path: "zenstruck_schedule.mailer").
(2/2) CommandTask: Send the weekly sales report
-----------------------------------------------
Expand All @@ -129,7 +129,7 @@ $ bin/console schedule:list --detail
[WARNING] 1 issue with schedule:
[ERROR] To use "onSingleServer" you must configure a lock factory (config path:
"zenstruck_schedule.single_server_handler").
"zenstruck_schedule.single_server_lock_factory").
```

There are two issues that need to be resolved in the bundle config:
Expand All @@ -138,8 +138,8 @@ There are two issues that need to be resolved in the bundle config:
# config/packages/zenstruck_schedule.yaml
zenstruck_schedule:
single_server_handler: lock.default.factory # required to use "onSingleServer"
email_handler: # required to use "emailOnFailure"
single_server_lock_factory: lock.default.factory # required to use "onSingleServer"
mailer: # required to use "emailOnFailure"
service: mailer
default_from: [email protected]
```
Expand Down
Loading

0 comments on commit 76636e5

Please sign in to comment.