stylers / laravel-task-manager
This package is a workaround for run tasks without artisan because proc_open & proc_close PHP modules disabled some server such as shared hosts.
6.0.0
2024-01-03 15:35 UTC
Requires
- php: >=8.1
- illuminate/support: ^10
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.18 || ^3.44
- orchestra/testbench: ^8.0
- phpmd/phpmd: ^2.15
- phpunit/phpunit: ^7.5.15 || ^8.4 || ^9.5.4 || ^10.0
This package is auto-updated.
Last update: 2024-11-03 17:23:31 UTC
README
Laravel version compatibility
Requirements
- PHP >= 8.0
- Laravel >= 9.x
Installation
composer require stylers/laravel-task-manager
How to Test
docker run -it --rm -v $PWD:/app -w /app composer sh
composer install
./vendor/bin/phpunit
Usage
TaskTimer trait is using Laravel's Schedule Frequency Options
- Add Interface and Trait to class implementation and add handle method for a command entrypoint
use Illuminate\Console\Command; use Stylers\TaskManager\Contracts\TaskTimerInterface; use Stylers\TaskManager\Traits\TaskTimer; class CommandTask extends Command implements TaskTimerInterface { use TaskTimer; public function handle() { // } }
- Add CommandTask to TaskManager
use Illuminate\Support\ServiceProvider; use Stylers\TaskManager\Console\TaskManager; use Stylers\TaskManager\Tests\Fixtures\CommandTask; class ScheduleServiceProvider extends ServiceProvider { public function boot() { parent::boot(); $this->app->booted(function () { $scheduler = app(TaskManager::class); // Single task adding $scheduler->addTasks( (new CommandTask())->dailyAt('6:00') ); // ---- OR ---- // Multiple task adding in same time $scheduler->bulkAddTasks([ (new CommandTask())->dailyAt('6:00'), (new CommandTask())->weekly(), ]); }); } }
- In example called in web.php
(please feel free to add security checks for endpoint)
use Stylers\TaskManager\Console\TaskManager; use Illuminate\Support\Facades\Route; Route::get('/cron', static function () { TaskManager::run(); });
- Set cron to call this endpoint
* * * * * curl -s -X GET -L domain/cron >>/var/log/cron.log 2>&1
Special thanks to:
- WebInvention (for this blog post)