Skip to content

Replace fixed cron jobs with dynamic cron job array in deploy.php#23

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-20
Draft

Replace fixed cron jobs with dynamic cron job array in deploy.php#23
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-20

Conversation

Copilot AI commented Aug 5, 2025

Copy link
Copy Markdown
Contributor

This PR replaces the hardcoded cron job system with a flexible, user-configurable dynamic array system that allows users to define their own cron jobs directly in their deploy.php file.

What Changed

Removed: Fixed/legacy cron job entries that were automatically generated based on detected Composer packages.

Added: A new lameco_cron_jobs parameter that accepts cron job configurations in multiple flexible formats:

// Array format (recommended for readability)
set('lameco_cron_jobs', [
    ['* * * * *', 'php craft queue/run'],
    ['0 2 * * *', 'php craft gc'],
    ['*/15 * * * *', 'php artisan schedule:run'],
]);

// String format (compact)
set('lameco_cron_jobs', [
    '* * * * * php craft queue/run',
    '0 2 * * * php craft gc',
]);

// Mixed format support
set('lameco_cron_jobs', [
    ['* * * * *', 'php craft queue/run'],
    '0 2 * * * php craft gc',
]);

Key Features

  • Automatic working directory handling: The system automatically prepends cd {{current_path}} && to commands that don't already include a working directory change
  • Multiple input formats: Supports array format, string format, and mixed configurations
  • Smart path detection: Respects existing cd commands in user-provided cron jobs
  • Robust error handling: Gracefully handles malformed inputs, whitespace, and edge cases

Backward Compatibility

Zero breaking changes - existing projects continue to work unchanged:

  • If no custom jobs are defined, the system automatically detects Craft CMS packages (Blitz, Formie) and creates the same cron jobs as before
  • Users can gradually migrate by adding custom jobs alongside auto-detection
  • Full migration is possible by disabling auto-detection: set('lameco_auto_detect_cron', false)

Migration Examples

// Option 1: Keep existing behavior (no changes needed)
// Auto-detection continues to work

// Option 2: Add custom jobs alongside auto-detection
set('lameco_cron_jobs', [
    ['*/5 * * * *', 'php artisan horizon:snapshot'],
]);

// Option 3: Explicit migration (recommended for new projects)
set('lameco_auto_detect_cron', false);
set('lameco_cron_jobs', [
    ['5 * * * *', '{{bin/php}} craft blitz/cache/refresh-expired'],
    ['5 * * * *', '{{bin/php}} craft formie/gc/prune-data-retention-submissions'],
    ['* * * * *', 'php craft queue/run'],
]);

Additional Improvements

  • Code cleanup: Removed duplicated configuration code in config.php
  • Enhanced documentation: Updated README with comprehensive examples and migration guide
  • New parameters: Added lameco_cron_jobs and lameco_auto_detect_cron configuration options

This change makes cron management significantly more flexible and user-friendly while maintaining full backward compatibility for existing deployments.

Fixes #20.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits August 5, 2025 09:04
Co-authored-by: kevinsleegerslameco <217211989+kevinsleegerslameco@users.noreply.github.com>
Co-authored-by: kevinsleegerslameco <217211989+kevinsleegerslameco@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace fixed cron jobs with dynamic cron job array in deploy.php Replace fixed cron jobs with dynamic cron job array in deploy.php Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace fixed cron jobs with dynamic cron job array in deploy.php

2 participants