deployment and operations
Scheduled Tasks
Make The Command Safe To Run Manually
- Expose work as a CLI command.
- Prevent unsafe overlap.
- Log counts and return meaningful exit codes.
Remember The Scheduler Environment
- Run manually first.
- Configure schedule externally.
- Monitor missed and failed runs.
Prevent Unsafe Overlap
- Cron environment differs from interactive shells.
- Overlapping work duplicates effects.
- Unbounded jobs grow until they fail.
Cron Shape
17 2 * * * cd /srv/shop/current && php bin/console cleanup-expired-tokens
Run the command manually in staging before adding a schedule. Confirm its working directory, PHP binary, environment variables, output, exit code, and retry behaviour. Operators should be able to see the last success and failure rather than discovering a missed task from a customer report.
Practice
Practice: Deploy A Cleanup Schedule
Plan the deployment of a nightly expired-token cleanup command. Explain how you prevent overlap and how an operator can tell whether the last run succeeded.
Requirements
- Expose work as a CLI command.
- Prevent unsafe overlap.
- Log counts and return meaningful exit codes.
- Run manually first.
- Configure schedule externally.
- Monitor missed and failed runs.
Show solution
Expose the cleanup as a bounded CLI command that logs counts and returns a meaningful exit code. Run it manually in staging with the same PHP binary, working directory, and environment the scheduler will use.
Add a lock when overlapping runs could duplicate work or overload the database. Configure the external schedule and monitor last success, last failure, and runtime so a silent missed job becomes visible.