A cron job runs a command inside one of your services on a schedule: clearing expired sessions every hour, sending a report every morning, draining a queue every five minutes. You add it to the service that has the code it needs; there is no separate worker to deploy.
Create a job
Open the service and go to Settings → Automations. Add a job and fill in:
- Name and, if you like, a description.
- Schedule. Pick a common one, such as hourly or daily, or write any cron expression, for example
0 3 * * *for every day at 03:00. - Time zone. The schedule follows the time zone you choose, so 09:00 stays 09:00 for your team.
- Shell.
bashorsh, depending on what the image has. - Command. What to run, exactly as you would type it in the container, such as
npm run cleanuporpython manage.py clearsessions.
Jobs can be switched off without deleting them.
How a job runs
When the schedule fires, Hangar runs the command inside the service's running container. It sees the same files, environment variables and private network as the service itself, so it can reach your databases the same way the app does.
Because the job runs in the existing container, the service has to be running. If it is stopped, the run fails and its log says that no container was found.
Docker Compose
In a Docker Compose service, choose which of the compose file's services the command runs in.
History and logs
Each job keeps a history of its runs with their logs, so you can see when it ran and what it printed. Use the run button to start a job immediately, which is the quickest way to check a new command.