Download the PHP package chriskonnertz/jobs without Composer
On this page you can find all versions of the php package chriskonnertz/jobs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chriskonnertz/jobs
More information about chriskonnertz/jobs
Files in chriskonnertz/jobs
Informations about the package jobs
Jobs
Minimalistic Cron job manager. Register jobs and the job manager will execute them automatically depending on their interval.
NOTE: This is not a queue manager and therefore this has nothing to do with Laravel's queue component. Also note that Laravel 5 has an integrated task scheduler that works similar to this library.
Installation
This library requires PHP >= 7.0
Add chriskonnertz/jobs
to composer.json
:
"chriskonnertz/jobs": "3.*"
Or via a console:
In the future run composer update
to update to the latest version of this library.
Framework support
This library supports Laravel >=5.5 with a service provider. Add the service provider to the config file config/app.php
:
To create an alias for the facade, add this new entry in this file:
Introduction
Create a concrete job class:
Instantiate the job manager:
If you use Laravel with the service provider you do not have to worry about this. The service provider will inject the cache dependency. In any other case the cache class has to implement the cache interface (
CacheInterface
). Take a look at theLaravelCache
class (that is meant for Laravel integration) for an example implementation.
Register the job:
Execute the registered jobs:
Automatically execute jobs
If your application is built on top of Laravel, you will have access to an Artisan command: php artisan jobs
This command will call Jobs::run()
to execute the jobs. Therefore you can add a Cron job to the crontab to start the command, for example 1 * * * * php /var/www/laravel/artisan jobs
. This will execute the Artisan command every minute. We recommend to run the Cron job every minute.
Methods of the jobs manager
Note: Some of these methods may throw a
JobException
.
Determine if a job exists in the pool
Add a job to the pool (without lazy loading)
Add a job to the pool (with lazy loading)
We recommend using addLazy()
over add()
.
Remove a job from the pool
Remove all jobs from the pool
Count the jobs
Get the remaining cool down
Get the timestamp of the last iteration
Set the minimum cool down time for all jobs
The minimum value and the initial value is one minute. Most likely there is no reason to change this value ever.
Set the cache key namespace
The job class
A job class implements the job interface. Therefore it has to implement these methods:
The AbstractJob
class actually implements these methods so we recommend to let your concrete job classes inherit from this class. The abstract class provides the attributes name
, active
and interval
that inheriting classes may overwrite.
The interval
Per default (as long as the inheriting job class does not overwrite it) the getInterval()
is a simple getter
for the interval
attribute. The interval
attribute defines the duration of the job's cool down in minutes. For example if it is 60
minutes (= 1
hour) the job is executed once per hour (max).
Status
Status of this repository: Deprecated. Issues will be fixed but no new feature implemented.