-
-
Notifications
You must be signed in to change notification settings - Fork 5
Background cron tasks
Some WebEngine projects need work to happen outside the normal request cycle. That is where background cron tasks fit in.
Typical cron jobs include:
- refreshing cached remote data
- sending queued emails or notifications
- importing data from third-party services
- cleaning up expired temporary files
These tasks should not wait for a browser request. They are better run on a schedule.
To define scheduled tasks for a project, add a crontab file in the project root.
That file contains schedule expressions and the commands to run when each schedule becomes due. WebEngine can then watch that file during development and execute the due commands locally.
Keep the commands project-relative and focused on application work. For example, a cron task might run a PHP script from cron/, refresh generated files in cache/, or call a CLI entry point inside your application.
During local development, gt run can keep the cron watcher running alongside the web server and asset build watcher. That makes scheduled tasks part of the same development loop as page requests.
If you want to work with the scheduled tasks on their own, use gt cron.
See [[gt commands#gt cron]] for the available flags such as watch mode, validation, and explanation output.
In production, the exact scheduling mechanism depends on your hosting environment. The important requirement is that the same commands your project expects are run on the intended schedule.
Treat scheduled jobs like any other application code: keep them version-controlled, predictable, and easy to test manually.
Move back to Run an application, or continue to the request-response lifecycle.
- File-based routing
- Page views
- Page logic
- Dynamic URIs
- Headers and footers
- Custom HTML components
- Page partials
- Binding data to the DOM
- DOM manipulation
- Hello You tutorial
- Todo list tutorial
- Address book tutorial WIP
- Blueprints
- Application architecture
- Coding styleguide WIP
- PHP environment setup WIP
- Web servers WIP
- Background cron tasks
- Database setup WIP
- Client-side compilation WIP
- Testing WebEngine applications WIP
- Production checklist WIP
- Security WIP