laravel-task-scheduling
Best practices for Laravel task scheduling including defining schedules, frequency constraints, overlap prevention, and monitoring hooks.
What this skill does
# Task Scheduling
## Defining Schedules in routes/console.php
```php
<?php
use Illuminate\Support\Facades\Schedule;
// Schedule an Artisan command
Schedule::command('reports:generate')->daily();
// Schedule a job
Schedule::job(new ProcessDailyMetrics)->dailyAt('01:00');
// Schedule a closure
Schedule::call(function () {
Cache::flush();
})->weekly();
// Schedule a shell command
Schedule::exec('node /home/forge/script.js')->daily();
```
## Schedule Types
### Artisan Commands
```php
// With arguments and options
Schedule::command('emails:send', ['--force'])->daily();
Schedule::command('reports:generate --type=weekly')->sundays();
// Using command class
Schedule::command(SendEmailsCommand::class, ['--force'])->daily();
```
### Queued Jobs
```php
// Dispatch a job
Schedule::job(new CleanUpExpiredTokens)->daily();
// Dispatch to a specific queue and connection
Schedule::job(new ProcessAnalytics, 'analytics', 'redis')->hourly();
```
### Closures
```php
Schedule::call(function () {
DB::table('sessions')
->where('last_activity', '<', now()->subHours(24))
->delete();
})->hourly()->description('Clean expired sessions');
```
### Shell Commands
```php
Schedule::exec('pg_dump mydb > /backups/db.sql')->daily();
```
## Frequency Methods
```php
// Common frequencies
Schedule::command('task')->everyMinute();
Schedule::command('task')->everyTwoMinutes();
Schedule::command('task')->everyFiveMinutes();
Schedule::command('task')->everyTenMinutes();
Schedule::command('task')->everyFifteenMinutes();
Schedule::command('task')->everyThirtyMinutes();
Schedule::command('task')->hourly();
Schedule::command('task')->hourlyAt(17); // At :17 past each hour
Schedule::command('task')->everyOddHour();
Schedule::command('task')->everyTwoHours();
Schedule::command('task')->everyThreeHours();
Schedule::command('task')->everyFourHours();
Schedule::command('task')->everySixHours();
Schedule::command('task')->daily();
Schedule::command('task')->dailyAt('13:00');
Schedule::command('task')->twiceDaily(1, 13); // At 1:00 and 13:00
Schedule::command('task')->twiceDailyAt(1, 13, 15); // At 1:15 and 13:15
Schedule::command('task')->weekly();
Schedule::command('task')->weeklyOn(1, '8:00'); // Monday at 8:00
Schedule::command('task')->monthly();
Schedule::command('task')->monthlyOn(4, '15:00'); // 4th of month at 15:00
Schedule::command('task')->twiceMonthly(1, 16); // 1st and 16th
Schedule::command('task')->lastDayOfMonth('17:00');
Schedule::command('task')->quarterly();
Schedule::command('task')->quarterlyOn(4, '14:00'); // 4th day of quarter
Schedule::command('task')->yearly();
Schedule::command('task')->yearlyOn(6, 1, '17:00'); // June 1st at 17:00
// Cron expression
Schedule::command('task')->cron('0 */6 * * *'); // Every 6 hours
```
## Constraints
### Time Constraints
```php
// Between specific times
Schedule::command('task')->hourly()->between('8:00', '17:00');
// Outside specific times
Schedule::command('task')->hourly()->unlessBetween('23:00', '04:00');
```
### Day Constraints
```php
Schedule::command('task')->daily()->weekdays();
Schedule::command('task')->daily()->weekends();
Schedule::command('task')->daily()->sundays();
Schedule::command('task')->daily()->mondays();
Schedule::command('task')->daily()->tuesdays();
Schedule::command('task')->daily()->wednesdays();
Schedule::command('task')->daily()->thursdays();
Schedule::command('task')->daily()->fridays();
Schedule::command('task')->daily()->saturdays();
Schedule::command('task')->daily()->days([0, 3]); // Sunday and Wednesday
```
### Environment Constraints
```php
// ✅ Only run in production
Schedule::command('analytics:process')->daily()->environments(['production']);
// ✅ Skip in testing
Schedule::command('reports:send')->daily()->environments(['production', 'staging']);
```
### Conditional Constraints
```php
// Run only when condition is true
Schedule::command('emails:send')
->daily()
->when(function () {
return config('services.email.enabled');
});
// Skip when condition is true
Schedule::command('maintenance:run')
->daily()
->skip(function () {
return app()->isDownForMaintenance();
});
```
## Overlap Prevention
```php
// ✅ Prevent overlapping: skip if previous instance is still running
Schedule::command('reports:generate')
->hourly()
->withoutOverlapping();
// With custom expiration (default is 24 hours)
Schedule::command('reports:generate')
->hourly()
->withoutOverlapping(expiresAt: 60); // Lock expires after 60 minutes
```
## Distributed Environments (onOneServer)
```php
// ✅ Only run on a single server (requires memcached, redis, or database cache driver)
Schedule::command('reports:generate')
->daily()
->onOneServer();
// Combine with overlap prevention
Schedule::command('analytics:process')
->hourly()
->onOneServer()
->withoutOverlapping();
```
## Schedule Groups
```php
// ✅ Apply shared configuration to multiple scheduled tasks
Schedule::command('analytics:aggregate')
->daily()
->onOneServer()
->withoutOverlapping()
->emailOutputOnFailure('[email protected]');
Schedule::command('analytics:cleanup')
->daily()
->onOneServer()
->withoutOverlapping()
->emailOutputOnFailure('[email protected]');
// Group with shared config (if using a helper)
collect([
'analytics:aggregate',
'analytics:cleanup',
'analytics:summary',
])->each(function ($command) {
Schedule::command($command)
->daily()
->onOneServer()
->withoutOverlapping()
->emailOutputOnFailure('[email protected]');
});
```
## Hooks (before, after, onSuccess, onFailure, ping)
```php
Schedule::command('reports:generate')
->daily()
->before(function () {
Log::info('Starting report generation...');
})
->after(function () {
Log::info('Report generation complete.');
})
->onSuccess(function () {
Notification::route('slack', '#ops')
->notify(new ScheduledTaskSucceeded('reports:generate'));
})
->onFailure(function () {
Notification::route('slack', '#alerts')
->notify(new ScheduledTaskFailed('reports:generate'));
});
```
### Pinging URLs (Health Checks)
```php
// Ping a URL before and after
Schedule::command('reports:generate')
->daily()
->pingBefore('https://health.example.com/start')
->thenPing('https://health.example.com/end');
// Ping only on success or failure
Schedule::command('reports:generate')
->daily()
->pingOnSuccess('https://health.example.com/success')
->pingOnFailure('https://health.example.com/failure');
// Works with services like Oh Dear, Healthchecks.io, Cronitor
Schedule::command('reports:generate')
->daily()
->pingBefore('https://hc-ping.com/your-uuid/start')
->thenPing('https://hc-ping.com/your-uuid');
```
### Email Output
```php
Schedule::command('reports:generate')
->daily()
->sendOutputTo('/var/log/reports.log')
->emailOutputTo('[email protected]');
// Only email on failure
Schedule::command('reports:generate')
->daily()
->emailOutputOnFailure('[email protected]');
```
## Sub-Minute Scheduling
```php
// ✅ Run every second (Laravel 11+)
Schedule::call(function () {
// Process real-time data
MetricsCollector::capture();
})->everySecond();
// Every 10 seconds
Schedule::call(function () {
QueueMonitor::check();
})->everyTenSeconds();
// Every 15 seconds
Schedule::command('queue:monitor')->everyFifteenSeconds();
// Every 20 / 30 seconds
Schedule::call(fn () => HealthCheck::ping())->everyTwentySeconds();
Schedule::call(fn () => HealthCheck::ping())->everyThirtySeconds();
```
## Output Management
```php
// Send output to a file
Schedule::command('reports:generate')
->daily()
->sendOutputTo('/var/log/schedule/reports.log');
// Append output to a file
Schedule::command('reports:generate')
->daily()
->appendOutputTo('/var/log/schedRelated in Productivity
gitea-workflow
IncludedOrchestrate agile development workflows for Gitea repositories using the tea CLI. Use when working with Gitea-hosted repos and asking to 'run the workflow', 'continue working', 'what's next', 'complete the task cycle', 'start my day', 'end the sprint', 'implement the next task', or wanting guided step-by-step development assistance. Keywords: workflow, orchestrate, agile, task cycle, sprint, daily, implement, review, PR, standup, retrospective, gitea, tea.
microsoft-graph-gateway
IncludedRoute Microsoft Graph work in this workspace. Use when users want to read or write Outlook mail, calendar events, contacts, OneDrive or SharePoint files, Teams, Planner, To Do, users, groups, directory data, or arbitrary Microsoft Graph endpoints from VS Code. Prefer WorkIQ for common read scenarios. Use Microsoft Graph for write actions and gap-read scenarios that need exact Graph properties, filters, permissions, or endpoints.
copilotkit
IncludedUse when building with CopilotKit — setup, development, integrations, debugging, upgrading, or contributing. Routes to the appropriate specialized skill based on the task.
wordly-wisdom
IncludedProvides calibrated decision analysis using Charlie Munger-style multiple mental models, inversion, incentive mapping, circle-of-competence checks, misjudgment audits, second-order effects, and forecast updates. Use when the user asks for an oracle take, a hard call, a decision memo, a premortem, an outside view, a red-team, a sanity-check, what am I missing, think this through, or wants a strategy, hire, investment, plan, product, partnership, or major life choice analysed. Avoid for simple factual lookups or time-sensitive legal, medical, or market questions without fresh evidence.
swain-session
IncludedSession management and project status dashboard. Owns the full session lifecycle (start/work/close/resume), focus lane, bookmarks, worktree detection, and tab naming. Also serves as the project status dashboard — shows active epics, progress, actionable next steps, blocked items, tasks, GitHub issues, and recommendations. Worktree creation is deferred to swain-do task dispatch (SPEC-195). Triggers on: 'session', 'status', 'what's next', 'dashboard', 'overview', 'where are we', 'what should I work on', 'show me priorities', 'bookmark', 'focus on', 'session info'.
gandi
IncludedComprehensive Gandi domain registrar integration for domain and DNS management. Register and manage domains, create/update/delete DNS records (A, AAAA, CNAME, MX, TXT, SRV, and more), configure email forwarding and aliases, check SSL certificate status, create DNS snapshots for safe rollback, bulk update zone files, and monitor domain expiration. Supports multi-domain management, zone file import/export, and automated DNS backups. Includes both read-only and destructive operations with safety controls.