draw/cron-job
Manage cron jobs stored in the database: queue due jobs and execute them via Symfony Messenger workers. Includes console commands to enqueue due jobs or run by name, optional Sonata Admin pages, and Doctrine ORM mapping configuration.
cron.d entries or Laravel’s schedule:run, offering runtime configurability without redeployments.CronJobExecution entity provides built-in logging for job outcomes, durations, and retries, addressing a critical gap in Laravel’s native scheduler (which lacks persistent execution history).Schema::create for Doctrine tables).symfony/messenger pinned to a compatible version).CronJob, CronJobExecution) may lack migrations or conflict with Laravel’s schema. Manual adjustments or custom migration scripts may be needed.spatie/laravel-messenger) to reduce friction?php artisan queue:work) when introducing Symfony Messenger?CronJob, CronJobExecution) be managed in Laravel’s migration system? Will manual schema adjustments be required?spatie/laravel-doctrine) to bridge Doctrine and Eloquent?failed_jobs table)?// app/Repositories/CronJobRepository.php
class CronJobRepository {
public function findByName(string $name) {
return CronJob::query()->where('name', $name)->first(); // Eloquent facade
// OR: return $this->doctrineEntityManager->find(CronJob::class, $name);
}
}
CronJobProcessor that dispatches jobs to Illuminate\Bus\Queue.CronJobExecuted, CronJobFailed).app/Console/Kernel.php or cron.d) and map them to the package’s database model.php artisan queue:work and Symfony’s messenger:consume).queue-due, queue-by-name) for execution.CronJobProcessor that pushes jobs to Illuminate\Bus\Queue.
// app/Services/CronJobProcessor.php
class CronJobProcessor {
public function execute(CronJob $cronJob) {
dispatch(new ExecuteCronJobJob($cronJob))->onQueue('cron');
}
}
Schema::create for Doctrine tables or adopt a multi-ORM strategy (e.g., spatie/laravel-doctrine).Schema::create('cron_jobs', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('command');
$table->string('schedule');
$table->timestamps();
});
TransportFactory or using a custom CronJobMessage handler:
# config/packages/messenger.yaml
framework:
messenger:
transports:
async: 'doctrine://default' # Use Doctrine transport (Laravel-compatible)
routing:
'Draw\Component\CronJob\Message\ExecuteCronJobMessage': async
// routes/web.php
Route::get('/admin/cron-jobs', [CronJobController::class, 'index']);
draw/cron-job, symfony/messenger, doctrine/orm, and Laravel’s queue drivers (Redis/database).draw_framework_extra and messenger routing in config/services.yaml (or Laravel’s config).CronJob and CronJobExecution (adapt Doctrine schema to Laravel’s migrations).php artisan queue:work --queue=cron) and stop Symfony’s messenger consumer (or configure it to use Laravel’s transports).queue-due command and manual triggers (queue-by-name).CronJobExecution and integrate with Laravel’s Horizon or custom monitoring.How can I help you explore Laravel packages today?