Laravel Cron Scheduling - The ability to run the Laravel task scheduler using different crons

Overview

Laravel Cron Scheduling

Laravel Task Scheduling is a great way to manage the cron. But the documentation contains the following warning:

By default, multiple tasks scheduled at the same time will execute sequentially based on the order they are defined in your schedule method. If you have long-running tasks, this may cause subsequent tasks to start much later than anticipated.

The runInBackground() method can help you. But!

The runInBackground method may only be used when scheduling tasks via the command and exec methods.

What should I do if I use code instead of running commands?..

Using our package, you can run as many cron as you want on the server, specifying its name for each one. And in the App\Console\Kernel you can specify which cron should handle this task in the onCron() method. A сron launched without specifying a name will be considered a default cron. You don't need to specify anything to put a task in this cron.

Install

Run:

    composer require adiafora/laravel-cron-schedule

Usage

App\Console\Kernel

In the App\Console\Kernel, replace the line:

    use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

with this:

    use Adiafora\Schedule\Kernel as ConsoleKernel;

Server

Now delete the cron entry on your server:

 * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

And add an entry instead:

 * * * * * cd /path-to-your-project && php artisan cron-schedule:run >> /dev/null 2>&1

Your scheduler is working now as before.

Another cron

You can add another cron to your server by specifying its name using the option --cron=. Let's give it a name longTime:

 * * * * * cd /path-to-your-project && php artisan cron-schedule:run --cron=longTime >> /dev/null 2>&1

And now you can specify the name of this cron for any task in the scheduler.

    $schedule->call(function () {
        $this->mailService->send();
        sleep(60);
        $this->mailService->send(true);
    })
        ->onCron('longTime')
        ->dailyAt('03:00');

    $schedule->call(function () {
        $this->report->prepare();
    })
        ->dailyAt('03:00');

Note that the task of preparing the report will work exactly at 03:00, without waiting for the emails sending! This way you can create as many crones as you want, give them names and assign tasks to them, distributing them as you see fit. And in each cron, the task will be launched strictly at the specified time, without waiting for other tasks launched at the same time in other crones.

License

The MIT License (MIT). Please see License File for more information.

You might also like...
Cron expression generator built on php8
Cron expression generator built on php8

The most powerful and extendable tool for Cron expression generation Cron expression generator is a beautiful tool for PHP applications. Of course, th

Schedule and unschedule eloquent models elegantly without cron jobs
Schedule and unschedule eloquent models elegantly without cron jobs

Laravel Schedulable Schedule and Unschedule any eloquent model elegantly without cron job. Salient Features: Turn any Eloquent Model into a schedulabl

Cron Job Manager for Magento 2
Cron Job Manager for Magento 2

EthanYehuda_CronJobManager A Cron Job Management and Scheduling tool for Magento 2 Control Your Cron Installation In your Magento2 root directory, you

 Laravel-Tasks is a Complete Build of Laravel 5.2 with Individual User Task Lists
Laravel-Tasks is a Complete Build of Laravel 5.2 with Individual User Task Lists

An app of tasks lists for each individual user. Built on Laravel 5.2, using 5.2 authentication and middleware. This has robust verbose examples using Laravel best practices.

Modern task runner for PHP

RoboTask Modern and simple PHP task runner inspired by Gulp and Rake aimed to automate common tasks: writing cross-platform scripts processing assets

Awesome Task Runner

Bldr Simplified Build System/Task Runner Uses Yaml, JSON, XML, PHP, or INI for configs Quick Usage To develop, run ./script/bootstrap, and then ./scri

Pure PHP task runner

task/task Got a PHP project? Heard of Grunt and Gulp but don't use NodeJS? Task is a pure PHP task runner. Leverage PHP as a scripting language, and a

Modern task runner for PHP

RoboTask Modern and simple PHP task runner inspired by Gulp and Rake aimed to automate common tasks: writing cross-platform scripts processing assets

A unified front-end for different queuing backends. Includes a REST server, CLI interface and daemon runners.

PHP-Queue A unified front-end for different queuing backends. Includes a REST server, CLI interface and daemon runners. Why PHP-Queue? Implementing a

Owner
Sergey Zhidkov
PHP developer. Frameworks: Laravel, Yii2
Sergey Zhidkov
xcron - the souped up, modernized cron/Task Scheduler for Windows, Mac OSX, Linux, and FreeBSD server and desktop operating systems.

xcron is the souped up, modernized cron/Task Scheduler for Windows, Mac OSX, Linux, and FreeBSD server and desktop operating systems. MIT or LGPL.

CubicleSoft 7 Nov 30, 2022
Manage your Laravel Task Scheduling in a friendly interface and save schedules to the database.

Documentation This librarian creates a route(default: /schedule) in your application where it is possible to manage which schedules will be executed a

Roberson Faria 256 Dec 21, 2022
PHP cron job scheduler

PHP Cron Scheduler This is a framework agnostic cron jobs scheduler that can be easily integrated with your project or run as a standalone command sch

Giuseppe Occhipinti 698 Jan 1, 2023
Flow Framework Task Scheduler

This package provides a simple to use task scheduler for Neos Flow. Tasks are configured via settings, recurring tasks can be configured using cron syntax. Detailed options configure the first and last executions as well as options for the class handling the task.

Flowpack 11 Dec 21, 2022
Dispatcher is a Laravel artisan command scheduling tool used to schedule artisan commands within your project so you don't need to touch your crontab when deploying.

Dispatcher Dispatcher allows you to schedule your artisan commands within your Laravel project, eliminating the need to touch the crontab when deployi

Indatus 1.1k Jan 5, 2023
Crunz is a framework-agnostic package to schedule periodic tasks (cron jobs) in PHP using a fluent API.

Crunz Install a cron job once and for all, manage the rest from the code. Crunz is a framework-agnostic package to schedule periodic tasks (cron jobs)

Reza Lavarian 1.4k Dec 26, 2022
:date: Easy!Appointments - Open Source Appointment Scheduler

Easy!Appointments A powerful Open Source Appointment Scheduler that can be installed on your server. About • Features • Setup • Installation • License

Alex Tselegidis 2.5k Jan 8, 2023
Cronlike scheduler running inside a ReactPHP Event Loop

Cronlike scheduler running inside a ReactPHP Event Loop Install To install via Composer, use the command below, it will automatically detect the lates

Cees-Jan Kiewiet 35 Jul 12, 2022
A PHP-based job scheduler

Crunz Install a cron job once and for all, manage the rest from the code. Crunz is a framework-agnostic package to schedule periodic tasks (cron jobs)

null 58 Dec 26, 2022
Manage all your cron jobs without modifying crontab. Handles locking, logging, error emails, and more.

Jobby, a PHP cron job manager Install the master jobby cron job, and it will manage all your offline tasks. Add jobs without modifying crontab. Jobby

null 1k Dec 25, 2022