Aptible PaaS logoDocs

Schedule Tasks

On Aptible, users typically run cron jobs as another service associated with an app, defined in the app's procfile, or run them as a separate app altogether.

To run cron jobs on Aptible, or any containerized environment, we recommend using Supercronic, a cron implementation Aptible created explicitly to be used with containers. Here's how to start running cron jobs for your app with Supercronic.

Step 1: Install Supercronic in your Docker image.

Step 2: Add a crontab to your repository. Here is an example crontab you might want to adapt or reuse:

# Run every minute
*/1 * * * * bundle exec rake some:task

# Run once every hour
@hourly curl -sf example.com >/dev/null && echo 'got example.com!'
📘 For a complete crontab reference, review the documentation from the library Supercronic uses to parse crontabs, cronexpr.
📘 Unless you've specified otherwise with the TZ environment variable, the schedule for your crontab will be interpreted in UTC.

Step 3: Copy the crontab to your Docker image with a directive such as this one:

ADD crontab /app/crontab
📘 The example above grabs a file named crontab found at the root of your repository and copies it under /app in your image. Adjust as needed.

Step 4: Add a new service (if your app already has a Procfile), or deploy a new app altogether to start Supercronic and run your cron jobs. If you are adding a service, use this Procfile declaration:

cron: exec supercronic /app/crontab

If you are adding a new app, you can use the same Procfile declaration or add a CMD declaration to your Dockerfile:

CMD ["supercronic", "/app/crontab"]