

Github GitHub - robersonfaria/laravel-database-schedule: Manage your Laravel Tas...
source link: https://github.com/robersonfaria/laravel-database-schedule
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md
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.
Installation
- Run
composer require robersonfaria/laravel-database-schedule
- 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 whenAPP_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.
This route is protected by the viewDatabaseSchedule
gate controls access.
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]', ]); }); }
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:
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:
Known issues:
- Does not record run history when runInBackground is used
Credits
- That library was inspired by the library therezor/laravel-database-schedule
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK