Download the PHP package tobento/service-schedule without Composer
On this page you can find all versions of the php package tobento/service-schedule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package service-schedule
Schedule Service
A task schedule system for running tasks at specific intervals.
Table of Contents
- Getting started
- Requirements
- Highlights
- Documentation
- Usage
- Scheduling Tasks
- Running Scheduled Tasks
- Tasks
- Callable Task
- Command Task
- Invokable Task
- Ping Task
- Process Task
- Task Methods
- General Task Methods
- Schedule Task Methods
- Task Parameters
- After Parameter
- Before Parameter
- Failed Parameter
- Mail Parameter
- Monitor Parameter
- Ping Parameter
- Send Result To Parameter
- Skip Parameter
- Without Overlapping Parameter
- Task Schedule
- Cron Expression
- Dates
- Task Processor
- Task Result
- Task Results
- Schedule
- Schedule Processor
- Console
- Run Command
- List Command
- Events
- Learn More
- Running Scheduled Tasks Without Console
- Usage
- Credits
Getting started
Add the latest version of the schedule service project running this command.
Requirements
- PHP 8.0 or greater
Highlights
- Framework-agnostic, will work with any project
- Decoupled design
Documentation
Usage
Scheduling Tasks
To schedule a task you may use the default Schedule or create your own fitting your needs.
Running Scheduled Tasks
The most common way to run the schedule processor is a Cron job that runs the schedule:run every minute. The following should be added to your production server's crontab:
Example of console.php
Example using the Console Service, Clock Service and Container Service:
Tasks
Callable Task
Check out the Task Parameters.
Invokable objects
You may consider using invokable objects that contain an method:
Command Task
The command task may be used to run the provided command using the Console Service.
Check out the Task Parameters.
Requirements
This command task requires the Console Service:
Invokable Task
You may create invokable tasks by simply extending the . The method will be called when the task is being processed.
Check out the Task Parameters.
Ping Task
The ping task may be used to ping the provided URI.
Check out the Task Parameters.
Requirements
This ping task requires Guzzle, PHP HTTP client:
Process Task
The process task may be used to execute shell commands using the Symfony Process Component.
Check out the Task Parameters.
Requirements
This process task requires the Symfony Process Component:
Task Methods
All of the available Tasks supporting the following methods.
General Task Methods
Schedule Task Methods
Check out the Task Schedule section for the available task schedules.
You may consider using the cron generator already available:
Check out the Cron Expression Generator for more examples.
Task Schedule
Cron Expression
You may use the to define at which interval you want to run the task.
You may consider using the cron generator already available:
Check out the Cron Expression Generator for more examples.
Dates
You may use the to run tasks at specific dates every year.
Task Parameters
You may use the available parameters providing basic features for tasks or create custom parameters to add new features or customizing existing to suit your needs.
All of the available Tasks supporting the following parameters and its helper methods.
After Parameter
The after parameter executes the specified handler after the task is processed.
The will be passed to your handler. In addition, you may request any service being resolved (autowired) by the container passed to the task processor.
Before Parameter
The before parameter executes the specified handler before the task is processed.
The will be passed to your handler. In addition, you may request any service being resolved (autowired) by the container passed to the task processor.
Skip Task
You may throw a if you want to prevent the task from being processed not resulting in a failure.
Failed Parameter
The failed parameter executes the specified handler if the task fails.
The will be passed to your handler. In addition, you may request any service being resolved (autowired) by the container passed to the task processor.
Mail Parameter
The mail parameter may be used to send mails using the Mail Service before and/or after tasks are processed or when a task fails.
In addition, you may use the , and helper methods:
Requirements
This parameter requires the Mail Service:
First, install the mail service:
Finally, it requires the to be binded to your container passed to the Task Processor:
Example using the Container Service:
Message From Address
If you do not have defined a default from address, you will need to set it:
Message Contents
You may set a message subject otherwise the task name will be used instead:
A sent mail looks like:
Monitor Parameter
The monitor parameter may be used to monitor tasks processes such as the start time, running time and memeory usage.
Ping Parameter
The ping parameter may be used to ping the provided URI.
A header will be added to the request with a , or value depending on its processing state.
In addition, you may use the , and helper methods:
Requirements
This parameter requires Guzzle, PHP HTTP client:
Send Result To Parameter
The send result to parameter may be used to send the task result to the specified file.
In addition, you may use the and helper methods:
Skip Parameter
The skip parameter may be used to skip tasks if the parameter evalutes to . The parameter has a default priority of whereby it gets handled before any lower prioritized task parameters.
If using a callable, the will be passed to your callback function. In addition, you may request any service being resolved (autowired) by the container passed to the task processor.
Without Overlapping Parameter
The without overlapping parameter may be used to prevent tasks from overlapping.
Requirements
The parameter requires a to be binded to your container passed to the Task Processor:
Example using the Cache Service and Container Service:
Task Processor
The is responsible for processing tasks.
Process Task
Check out the Task Result to learn more.
Task Result
Task Results
Schedule
Example adding tasks
Check out the Tasks section for more information about the individual tasks.
Schedule Processor
The schedule processor is responsible for processing the scheduled tasks which are due.
Process Scheduled Task
To process tasks when they are due, the method should be called every minute indefinitely.
You may create a custom schedule processor fitting your needs though.
Check out the Task Results to learn more.
Console
You may use the following commands using the Console Service.
To get quickly started consider using the following two app bundles:
Otherwise, you need to install the Console Service and set up your console by yourself. Check out the Running Scheduled Tasks section to see a possible implementation.
Run Command
Running due tasks
Running specific tasks by its id
List Command
Lists all tasks.
Events
Available Events
Event | Description |
---|---|
The event will dispatch before the schedule is processed | |
The event will dispatch after the schedule is processed | |
The event will dispatch before the task is processed | |
The event will dispatch after the task is processed |
Just make sure you pass an event dispatcher to the Schedule Processor!
Learn More
Running Scheduled Tasks Without Console
Another way to run the schedule processor is a Cron job that runs your schedule.php script every minute. The following should be added to your production server's crontab:
Example of schedule.php
Example using the Container Service:
Credits
- Tobias Strub
- All Contributors
All versions of service-schedule with dependencies
psr/container Version ^2.0
psr/clock Version ^1.0
psr/simple-cache Version 2 - 3
psr/event-dispatcher Version ^1.0
tobento/service-autowire Version ^1.0.9
tobento/service-file-creator Version ^1.0.1
tobento/service-collection Version ^1.0.5
dragonmantank/cron-expression Version ^3.1
butschster/cron-expression-generator Version ^1.10