Manage your Laravel Task Scheduling in a friendly interface and save schedules to the database.

Overview

Laravel Database Schedule

Documentation

This librarian creates a route(default: /schedule) in your application where it is possible to manage which schedules will be executed at any given moment, these schedules are recorded in the database and can be changed, activated, inactivated or deleted via the interface without the need for a new application deployment.

List Schedules

Create Schedules

Show History Schedules

Installation

  1. Run composer require robersonfaria/laravel-database-schedule
  2. Run php artisan migrate

Environment variables

You can set the following environment variables to configure schedules:

  • SCHEDULE_TIMEZONE : The default is the same configured for the application, but if you need the schedules to run in a different timezone, it is possible to configure it with this variable
  • SCHEDULE_CACHE_DRIVER : The default is file
  • SCHEDULE_CACHE_ENABLE : The default is disabled when APP_DEBUG=true and enabled when APP_DEBUG=false

Configurations

There are several library configuration options, to change the settings you can get the configuration file for your project

php artisan vendor:publish --provider="RobersonFaria\DatabaseSchedule\DatabaseSchedulingServiceProvider" --tag="config"

Dashboard Authorization

Dashboard Authorization exposes a dashboard at /schedule URI.

In the configuration file it is possible to define whether to restrict access to route /schedule, the default is true. If access is restricted, the user must be logged in and meet the requirements defined in the viewDatabaseSchedule gate controls access.

<?php
return [
    //...
    /**
     * If restricted_access is true, the user must be authenticated and meet the definition of `viewDatabaseSchedule` gate
     */
    'restricted_access' => env('SCHEDULE_RESTRICTED_ACCESS', true),
    //...
]

Note that this value can also be changed using the SCHEDULE_RESTRICTED_ACCESS environment variable.

ATTENTION: if restricted_access is set to false, access to the / schedule route will be public.

You must define the gates in your service providers, laravel by default already brings the provider App\Providers\AuthServiceProvider for this purpose. See more in the Laravel documentation https://laravel.com/docs/8.x/authorization#gates

You are free to modify this gate as needed to restrict access to your Database Schedule Dashboard.

protected function gate()
{
    Gate::define('viewDatabaseSchedule', function ($user) {
        return in_array($user->email, [
            '[email protected]',
        ]);
    });
}

Exemples:

If you want to limit access to a route to users who have a certain role, you can do so.

Gate::define('viewDatabaseSchedule', function ($user) {
     return $user->hasRole('administrator');
});

Basically, if your gate has return true access will be allowed, if return false access will be restricted.

Scheduled Task Example

Create the command for your scheduled task app/Console/Commands/test.php:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:test {user} {initialDate} {finalDate}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $this->info('Hello ' . $this->argument('user'));
        $this->info("Initial Date: " . $this->argument('initialDate'));
        $this->info("Final Date: " . $this->argument('finalDate'));
        return 0;
    }
}

Access the dashboard and the command will be listed for scheduling, create a schedule like the example below: Create Schedule

Run the artisan command to run scheduled tasks

php artisan schedule:run

The console output will look like this

Running scheduled command: '/usr/bin/php7.2' 'artisan' command:test '1' '2021-02-10 00:00:00' '2021-04-10 00:00:00' > 'path/to/storage/logs/schedule-dcccb62f29f754dc83a86a3d0b59afb00a08fdb3.log' 2>&1

If you marked the sending of the output by email you will receive an email similar to this one:

Mail Output

Known issues:

  • Does not record run history when runInBackground is used

Credits

Comments
  • Update Readme to help out new folk

    Update Readme to help out new folk

    Hey,

    It would be great if you could add an example of how to modify the gate in the Dashboard Authorization section

    It's a crucial part of the install and not all users will be familiar with extending vendor Service Providers :+1:

    opened by JohnRoux 10
  • Arguments improvement

    Arguments improvement

    hi, package doesn't support arguments with no values for example:

    backup:run [--filename [FILENAME]] [--only-db] [--db-name [DB-NAME]] [--only-files] [--only-to-disk [ONLY-TO-DISK]] [--disable-notifications] [--timeout [TIMEOUT]]

    I want to execute command: backup:run --only-db without any other arguments. Now I get error The "--disable-notifications" option does not accept a value.

    I added new data type: "Disabled", it means that argument will not be added to a command. If you need argument - select "string" or "function". String type will create command string like "command arg=value" or "command arg" in case when inputed value is empty.
    In index.blade show only arguments which are in use in a command.

    2021-08-31_08-55-40 2021-08-31_08-55-52 2021-08-31_08-55-17

    PR changes: 2021-08-31_09-51-16 2021-08-31_09-51-45

    opened by andreypopov 7
  • `schedule:list` shows no configured schedules

    `schedule:list` shows no configured schedules

    Hi, i am using the very most recent laravel version v8.41.0 and unfortunately after installing robersonfaria/laravel-database-schedule the artisan schedule:list command is always returning nothing, regardless of what i configure in the backend:

    grafik

    # php artisan schedule:list
    +---------+----------+-------------+----------+
    | Command | Interval | Description | Next Due |
    +---------+----------+-------------+----------+
    #
    

    When removing robersonfaria/laravel-database-schedule again, the command displays the tasks defined in App\Console\Kernel.php again as it should. I know this once worked ! Possibly laravel/framework has changed something in recent versions? Can i provide any more debug information ? Or did i forget to register the module somewhere? I am out of clues. Thanks a lot !

    opened by thyseus 7
  • Arguments fix

    Arguments fix

    Assume we have a command:

            protected $signature = 'group:backup {server}';
    

    and configure laravel-database-schedule to run, currently it runs:

    php artisan group:backup server='my-server'

    which is wrong; it should run:

    php artisan group:backup my-server

    This MR fixes that problem.

    opened by thyseus 5
  • Duplicate output when send mail

    Duplicate output when send mail

    When you put an email to receive the output of the scheduled command, this out put is registred an sended twice.

    image

    To reproduce the error, run the command without send mail option, after that register an email in the command and run it again.

    opened by PedroPMS 4
  • Command parameters with comments are not recognized

    Command parameters with comments are not recognized

    Hi,

    at first - thanks a lot for this great repository.

    Unfortunately Commands that have Arguments with a comment are not recognized by laravel-database-schedule. Take this Example of the official telescope module:

    class PruneCommand extends Command
    {
        /**
         * The name and signature of the console command.
         *
         * @var string
         */
        protected $signature = 'telescope:prune {--hours=24 : The number of hours to retain Telescope data}';
    

    The argument --hours is not recognized and therefore can not be set:

    grafik

    The parameters are collected in src/Http/Services/CommandService.php but unfortunately i can not grasp why $command->getDefinition()->getArguments()) in line 31 does not retrieve commented arguments. Possibly this is a laravel issue ?

    Besides of that, how about an switch to enter a completely custom command as text field in addition to the dropdown for some special cases?

    bug 
    opened by thyseus 4
  • Update documentation

    Update documentation

    Various modifications and additions of new functionality have been made, it is necessary to update the documentation(README) to reflect all existing functionality.

    If anyone can contribute I appreciate it.

    opened by robersonfaria 3
  • fix: passing mapedArguments as array values

    fix: passing mapedArguments as array values

    I noticed a problem when passing the argument array to command creation.

    Passing an array in the format key => value, to the method that creates the command, these arguments are formatted like this: "key=value". As you can see in the prints:

    schedule->mapArguments(): image

    Argument debug: image

    Result: image

    To solve this it is necessary to transform the key => value array into a normal array using array_values().

    array_values(schedule->mapArguments()): image

    Argument debug: image

    Result: image

    opened by PedroPMS 3
  • avoid passing argument key to command line argument

    avoid passing argument key to command line argument

    Assume we have a command:

            protected $signature = 'group:backup {server}';
    

    and configure laravel-database-schedule to run, currently it runs:

    php artisan group:backup server='my-server'

    which is wrong; it should run:

    php artisan group:backup my-server

    This MR fixes that problem.

    opened by thyseus 2
  • Translation not working

    Translation not working

    Hello.

    I'm trying translate the UI to portuguese creating a file like schedule.php in my resources/lang/pt_BR folder, and this is not working. If I go to your package folder in vendor and add a pt_BR folder with my translations, it works.

    Anyway, I forked the project to add the pt_BR folder directly to your project and already do the translations. I'm sending the PR, this can help those who have projects in pt_BR

    opened by PedroPMS 2
  • Options to don't send email on command success

    Options to don't send email on command success

    This PR allow the user chose when he want to receive the email output.

    • On success
    • On failure
    • Both cases With simple buttons he can chose these options.

    Obs: Doing this PR I notice that if you uncheck the send mail option the command in database is not updated. So, I fixed this issue too.

    opened by PedroPMS 1
  • can't override viewDatabaseSchedule gate in custom or app service provider

    can't override viewDatabaseSchedule gate in custom or app service provider

    the existence of viewDatabaseSchedule in DatabaseScheduleApplicationServiceProvider.php is causing difficulty in overriding in AppServiceProvider or any custom ServiceProvider.

    i think you should remove it allow users to set it rather.

    opened by scryba 2
  • not able to change Timezone

    not able to change Timezone

    Hi, i am using this package and the documentation of this package says i can change timezone with the config file. I have tried but timezone is not picking value from package configuration file (SCHEDULE_TIMEZONE ).

    Also i want to put timezone according to user. is there a way to pass timezone in the $schedule array when creating new schedule?

    Thankyou

    opened by link2arslan 4
  • Setting verbosity not possible?

    Setting verbosity not possible?

    Hi, this might be a really stupid question, but I cannot seem to find a way to specify the verbosity. There is neither a dropdown nor a generic input where I could specify additional parameters like "-vv". Good logging is pretty important for my use case.

    opened by LMCom 2
  • Creation of new tests (PHPUnit)

    Creation of new tests (PHPUnit)

    The package is growing fast and new features are being added constantly, we need to write tests(PHPUnit) to cover most of the features. It's becoming more and more difficult to test and ensure that everything keeps working after a new pull request.

    opened by robersonfaria 0
  • In case of failure, duplicate emails are sent

    In case of failure, duplicate emails are sent

    When selecting to send email on success and failure, when a command fails, duplicate email is sent. I still haven't found a solution to the problem, apparently it's a behavior of the framework.

    Case also interests @PedroPMS

    opened by robersonfaria 2
Releases(1.3.2)
Owner
Roberson Faria
Roberson Faria
Task Scheduling with Cron Job in Laravel

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Shariful Islam 1 Oct 16, 2021
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
Modern and simple PHP task runner inspired by Gulp and Rake aimed to automate common tasks

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

Consolidation 2.6k Jan 3, 2023
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
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.

Jeremy Kenedy 26 Aug 27, 2022
A versatile and lightweight PHP task runner, designed with simplicity in mind.

Blend A versatile and lightweight PHP task runner, designed with simplicity in mind. Table of Contents About Blend Installation Config Examples API Ch

Marwan Al-Soltany 42 Sep 29, 2022
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

Consolidation 2.6k Jan 3, 2023
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

null 223 Nov 20, 2022
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

null 184 Sep 28, 2022
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

Consolidation 2.6k Dec 28, 2022
🐺 Asynchronous Task Queue Based on Distributed Message Passing for PHP.

?? Asynchronous Task Queue Based on Distributed Message Passing for PHP.

Ahmed 36 Aug 11, 2022
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
A PHP implementation of a bare task loop.

TaskLoop A PHP implementation of a bare task loop. Installation. $ composer require thenlabs/task-loop 1.0.x-dev Usage. The file example.php contains

ThenLabs 1 Oct 17, 2022
Reset the live preset for debug settings with a task

Debug Settings Task This TYPO3 extension resets TYPO3 debug settings to the »live« preset on production using a scheduler task. Vision “Better safe th

webit! Gesellschaft für neue Medien mbH 1 Aug 15, 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
Manage Your Laravel Schedule From A Web Dashboard

Introduction Manage your Laravel Schedule from a pretty dashboard. Schedule your Laravel Console Commands to your liking. Enable/Disable scheduled tas

ⓒⓞⓓⓔ ⓢⓣⓤⓓⓘⓞ 1.6k Jan 5, 2023
Manage Your Laravel Schedule From A Web Dashboard

Introduction Manage your Laravel Schedule from a pretty dashboard. Schedule your Laravel Console Commands to your liking. Enable/Disable scheduled tas

ⓒⓞⓓⓔ ⓢⓣⓤⓓⓘⓞ 1.6k Jan 1, 2023
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

CoderKungfu 646 Dec 30, 2022
A course database lookup tool and schedule building web application for use at Rochester Institute of Technology.

CSH ScheduleMaker A course database lookup tool and schedule building web application for use at Rochester Institute of Technology. Built, maintained

Computer Science House 55 Nov 8, 2022