Download the PHP package okvpn/cron-bundle without Composer
On this page you can find all versions of the php package okvpn/cron-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download okvpn/cron-bundle
More information about okvpn/cron-bundle
Files in okvpn/cron-bundle
Package cron-bundle
Short Description Docker friendly Symfony cron bundle for handle scheduled tasks consistently, parallel or across a cluster, like Symfony Messenger
License MIT
Homepage https://github.com/vtsykun/cron-bundle
Informations about the package cron-bundle
Okvpn - Cron Bundle
This bundle provides interfaces for registering and handle scheduled tasks within your Symfony application.
Purpose
This is a simpler alternative of existing cron bundle without doctrine deps. Here also added support middleware for customization handling cron jobs across a cluster install: (Send jobs to message queue, like Symfony Messenger; locking; etc.). This allows to limit the number of parallel running processes and prioritized it.
Features
- Not need doctrine/database.
- Docker friendly, runs as background command without
crond
. - Schedule tasks with one-millisecond precision.
- More ways to randomize crons with
@random 3600
andjitter
. - Integration with Symfony Messenger.
- Load a cron job from a different storage (config.yml, tagged services, commands).
- Support many engines to run cron (in parallel process, message queue, consistently).
- Support many types of cron handlers/command: (services, symfony commands, UNIX shell commands).
- Can be used along with timers, subscriber and async I/O with React EventLoop, like Redis subscriber clue/redis-react.
- Middleware and customization.
Table of Contents
- Install
- Commands
- Registration a new scheduled task
- Configuration
- Symfony Messenger Integration
- Your own Scheduled Tasks Loader
- Handling cron jobs across a cluster
- Use ReactPHP EventLoop
Install
Install using composer:
For Symfony 4+ add bundle to config/bundles.php
Quick Usage
You can use AsCron
or AsPeriodicTask
attribute for autoconfigure.
Commands
Runs the current cron schedule
Debug and execute cron jobs manually and show list
Dry run cron tasks.
Cron Expression
A CRON expression syntax was take from lib dragonmantank/cron-expressions
Also, it was extent with @random
to avoid running things at midnight or once an hour at XX:00.
Most people do so and same services have traffic peaks every hour.
Examples:
First way. Install system crontab
To regularly run a set of commands from your application, configure your system to run the oro:cron command every minute. On UNIX-based systems, you can simply set up a crontab entry for this:
Second way. Using supervisor
Setup Supervisor to run cron on demand.
Create a new supervisor configuration.
Add the following lines to the file.
Registration a new scheduled task
To add a new scheduled task you can use tag okvpn.cron
or using autoconfigure
with interface Okvpn\Bundle\CronBundle\CronSubscriberInterface
.
Services.
If you use the default configuration, the corresponding service will be automatically registered thanks to autoconfigure
.
To declare the service explicitly you can use the following snippet:
Possible options to configure with tags are:
cron
- A cron expression, if empty, the command will run always.lock
- Prevent to run the command again, if prev. command is not finished yet. Possible value:true
,{name: lock1, ttl: 300}
. To use this option need to install symfony lock componentasync
- Run command in the new process without blocking main thread.arguments
- Array of arguments, used to run symfony console commands or pass arguments to handler.priority
- Sorting priority.group
- Group name, see Cron Grouping section.jitter
- Random delay 0-60 secinterval
- Run periodic tasks by interval. Examples10
,10 seconds
,1 day
.messenger
- Send jobs into Messenger Bus. Defaultfalse
. You also can specify transport here{routing: async}
, see Symfony Routing Messages to a Transport
Symfony console command
Via configuration / shell commands
Full Configuration Reference
Handle Cron Jobs via Symfony Messenger
To limit the number of parallel running processes you can handle the cron jobs in the queue using Symfony Messenger.
- Install Symfony Messenger
-
Enable default route for cron job
- Enable Messenger for cron.
More information how to use messenger here
Your own Scheduled Tasks Loaders
You can create custom tasks loaders, see example
And register your loader.
Handling cron jobs across a cluster or custom message queue
You can use the cron $group
to split many scheduled tasks between clusters, see example:
See example of customization one, two
Use ReactPHP EventLoop
You can add your own periodic tasks directly to Loop
.
The bundle uses a simple wrapper Okvpn\Bundle\CronBundle\Runner\ScheduleLoopInterface
for the library react/event-loop
Configure ReactPHP adapter
Need to install react/event-loop if you want to use with async I/O, for example for handle websockets, redis.
License
MIT License.
All versions of cron-bundle with dependencies
symfony/framework-bundle Version ^4.4 || ^5.4 || ^6.0 || ^7.0
dragonmantank/cron-expression Version ^3.0