artemyurov / moonshine-command-schedule-job
Single entry point for Laravel scheduled commands and queued jobs with MoonShine admin UI
Package info
github.com/ArtemYurov/moonshine-command-schedule-job
pkg:composer/artemyurov/moonshine-command-schedule-job
Requires
- php: ^8.2
- illuminate/console: ^11.0|^12.0
- illuminate/database: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
- moonshine/moonshine: ^4.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0
- phpunit/phpunit: ^10.5|^11.0
Suggests
- ext-posix: Required for PID-based process termination
- artemyurov/moonshine-db-joblog: Required for PID-based job termination in CommandScheduleJobService
- illuminate/redis: Required for queue job deletion via Horizon
- laravel/horizon: Required for queue-based job deduplication and termination in CommandScheduleJobService
README
One class = artisan command + scheduler + queue job + admin UI.
Define a single service class — the package auto-registers an artisan command and scheduler entry, with a MoonShine admin panel for managing schedules at runtime.
Quick Start
class SyncAccountData extends CommandScheduleJobService { protected string $commandSignature = 'sync:account-data {--account-id=}'; protected string $commandDescription = 'Sync account data from external API'; protected ?string $scheduleFrequency = 'everyFiveMinutes'; protected ?string $jobClass = SyncAccountDataJob::class; protected function handle(array $params = []): void { $account = Account::findOrFail($params['account-id']); $this->dispatchJob($account); } }
php artisan sync:account-data --account-id=42
Installation
composer require artemyurov/moonshine-command-schedule-job php artisan migrate
Publish config (optional):
php artisan vendor:publish --tag=command-schedule-job-config
Features
- Console + Scheduler — every service automatically becomes an artisan command and a scheduler entry
- Queue Jobs — set
$jobClassto dispatch queued jobs with built-in deduplication - MoonShine Admin UI — toggle scheduler, configure frequency, view run times, copy commands
- Artisan Generator —
php artisan make:command-schedule-job-service MyService - Auto-discovery — scans configured directories for service classes
Service Discovery
The package auto-discovers services by scanning configured directories:
// config/command-schedule-job.php 'discovery' => [ 'paths' => ['app/Services/'], 'namespaces' => ['App\\Services'], ],
Any non-abstract class extending CommandScheduleJobService found in these paths will be auto-registered.
Service Properties
| Property | Type | Default | Description |
|---|---|---|---|
$commandSignature |
string |
required | Artisan command signature |
$commandDescription |
string |
required | Command description |
$scheduleFrequency |
?string |
null |
Schedule method (daily, hourly, everyFiveMinutes, etc.) |
$scheduleFrequencyArgs |
?array |
null |
Arguments for the frequency method |
$scheduleConsoleArgs |
?string |
null |
Extra console arguments for the scheduled command |
$jobClass |
?string |
null |
Job class to dispatch (null = sync execution) |
$withoutOverlappingJob |
bool |
true |
Check for active jobs before dispatch |
$withoutOverlappingJobExpiresAt |
?int |
null |
Lookup window in minutes (null = config default) |
Configuration
// config/command-schedule-job.php return [ 'discovery' => [ 'paths' => ['app/Services/'], 'namespaces' => ['App\\Services'], ], 'table' => 'command_schedule_jobs', 'default_without_overlapping_job_expires_at' => 180, ];
Optional Dependencies
| Package | What it enables |
|---|---|
laravel/horizon |
Queue-based job search and management |
artemyurov/moonshine-db-joblog |
PID-based precise job termination |
ext-posix |
PID-based process termination |
Core functionality works without these. Job deduplication and termination are enhanced when installed.
Requirements
- PHP 8.2+
- Laravel 11 or 12
- MoonShine 4.x
License
MIT