CLI and cron.
Reuse application services from explicitly registered commands and schedule them with the system cron.
A custom command
A command implements CommandInterface, receives arguments, and returns a process exit code. Its class is created only when selected, inside an isolated Command scope.
<?php
use Lemonade\Framework\Cli\CommandInterface;
final class ImportProductsCommand implements CommandInterface
{
public function name(): string { return 'products:import'; }
public function description(): string { return 'Import products.'; }
public function run(array $args): int
{
// Run the application operation and return a process exit code.
return 0;
}
}Inject CommandInput, CommandOutput, and CommandContext when structured console I/O is useful.
Registration and scheduling
Register a command name, class, and description in Commands.yaml. Run it through vendor/bin/lemonade; use cron or a supervisor for scheduling.
module: commands
config:
commands:
- name: products:import
class: App\Console\ImportProductsCommand
description: Import products from the configured source.
# cron: */15 * * * * cd /var/www/app && vendor/bin/lemonade products:importLemonade does not include a scheduler. Framework commands cover migrations, queue workers, and sitemap generation, among other operations.