{"id":16749644,"url":"https://github.com/chriskonnertz/jobs","last_synced_at":"2025-04-10T14:11:33.401Z","repository":{"id":22491962,"uuid":"25831347","full_name":"chriskonnertz/Jobs","owner":"chriskonnertz","description":"Simple Cron job manager. Register jobs and the job manager will automatically execute them depending on their interval.","archived":false,"fork":false,"pushed_at":"2019-04-23T13:43:08.000Z","size":132,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T09:23:41.270Z","etag":null,"topics":["automate","cron","job","jobs","laravel","manage","php","schedule","scheduling"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chriskonnertz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-27T17:45:41.000Z","updated_at":"2024-12-06T12:49:16.000Z","dependencies_parsed_at":"2022-08-21T09:20:20.553Z","dependency_job_id":null,"html_url":"https://github.com/chriskonnertz/Jobs","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskonnertz%2FJobs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskonnertz%2FJobs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskonnertz%2FJobs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chriskonnertz%2FJobs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chriskonnertz","download_url":"https://codeload.github.com/chriskonnertz/Jobs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248232444,"owners_count":21069487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automate","cron","job","jobs","laravel","manage","php","schedule","scheduling"],"created_at":"2024-10-13T02:25:29.489Z","updated_at":"2025-04-10T14:11:33.366Z","avatar_url":"https://github.com/chriskonnertz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Jobs\n\nMinimalistic Cron job manager. Register jobs and the job manager will execute them automatically depending on their interval.\n\n\u003e 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](https://laravel.com/docs/5.7/scheduling) that works similar to this library.\n\n## Installation\n\n\u003e This library requires PHP \u003e= 7.0\n\nAdd `chriskonnertz/jobs` to `composer.json`:\n\n    \"chriskonnertz/jobs\": \"3.*\"\n    \nOr via a console:\n\n```\ncomposer require chriskonnertz/jobs\n```\n\nIn the future run `composer update` to update to the latest version of this library.\n\n### Framework support\n\nThis library supports Laravel \u003e=5.5 with a service provider. Add the service provider to the config file `config/app.php`:\n\n```php\n    'providers' =\u003e array(\n        // ...\n        'ChrisKonnertz\\Jobs\\Integration\\JobsServiceProvider',\n    ),\n```\n\nTo create an alias for the facade, add this new entry in this file:\n\n```php\n    'aliases' =\u003e array(\n        // ...\n        'Jobs' =\u003e 'ChrisKonnertz\\Jobs\\Integration\\JobsFacade',\n        'AbstractJob' =\u003e 'ChrisKonnertz\\Jobs\\AbstractJob',\n    ),\n```\n\n## Introduction\n\nCreate a concrete job class:\n```php\n    class ExampleJob extends ChrisKonnertz\\Jobs\\AbstractJob \n    {\n\n        protected $name = 'exampleJob';\n\n        protected $interval = 5; // Run every five minutes\n\n        public function run(int $executedAt = null)\n        {\n            echo 'Hello World!';\n        }\n\n    }\n```\n\nInstantiate the job manager:\n```php\n    $cache = new ExampleCacheClass;\n    $jobs = new ChrisKonnertz\\Jobs\\Jobs($cache);\n```\n\n\u003e 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 the `LaravelCache` class (that is meant for Laravel integration) for an example implementation.\n\nRegister the job:\n```php\n    $jobs-\u003eaddLazy('updateStreams', 'ExampleJob');\n```\n\nExecute the registered jobs:\n```php\n    $jobs-\u003erun();\n```\n\n### Automatically execute jobs\n\nIf 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.\n\n## Methods of the jobs manager\n\n\u003e Note: Some of these methods may throw a `JobException`.\n\n### Determine if a job exists in the pool\n```php\n    $hasJob = $jobs-\u003ehas('exampleJob');\n```\n\n### Add a job to the pool (without lazy loading)\n```php\n    $job = new ExampleJob;\n    $jobs-\u003eadd($job);\n```\n\n### Add a job to the pool (with lazy loading)\n```php\n    // Pass the class name:\n    $jobs-\u003eaddLazy(\\My\\Example\\Job::class);\n\n    // Or pass a closure:\n    $jobs-\u003eaddLazy(function()\n    {\n        return new ExampleJob;\n    });\n```\n\nWe recommend using `addLazy()` over `add()`.\n\n### Remove a job from the pool\n```php\n    $jobs-\u003eremove('exampleJob');\n```\n\n### Remove all jobs from the pool\n```php\n    $jobs-\u003eclear();\n```\n\n### Count the jobs\n```php\n    $howMany = $jobs-\u003ecount();\n```\n\n### Get the remaining cool down\n```php\n$minutes = $jobs-\u003eremainingCoolDown();\n```\n    \n### Get the timestamp of the last iteration\n```php\n$timestamp =  $jobs-\u003elastRunAt();\n```\n### Set the minimum cool down time for all jobs\n```php\n    $jobs-\u003ecoolDown(1); // One minute\n```\n\nThe minimum value and the initial value is one minute. Most likely there is no reason to change this value ever.\n\n### Set the cache key namespace\n```php\n    $jobs-\u003ecacheKey('jobs.');\n```\n\n## The job class\n\nA job class implements the job interface. Therefore it has to implement these methods:\n\n```php\n    interface JobInterface \n    {\n\n        public function getName() : string; // The name (identifier) of the job\n\n        public function getActive() : bool; // Active or paused (=not executed)?\n\n        public function getInterval() : int; // The cool down time\n\n        public function run(int $executedAt = null); // The run method\n\n    }\n```\n\nThe `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.\n\n### The interval\n\nPer default (as long as the inheriting job class does not overwrite it) the `getInterval()` is a simple getter \nfor 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).\n\n## Status\n\nStatus of this repository: **Deprecated**. Issues will be fixed but no new feature implemented.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchriskonnertz%2Fjobs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchriskonnertz%2Fjobs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchriskonnertz%2Fjobs/lists"}