LEMONADE Documentation

Documentation.

Fifteen chapters covering installation, project structure, application development, CLI and production deployment.

Chapter 14 of 15

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.

ImportProductsCommand.php
<?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.

app/Config/Commands.yaml
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:import

Lemonade does not include a scheduler. Framework commands cover migrations, queue workers, and sitemap generation, among other operations.

Detailed technical documentation on GitHub