Cron Jobs
All cron jobs can be found in the /cron directory.
They must be run periodically through an external trigger, for instance through crontab or a service.
This page provides examples how we setup the cron jobs. Adjust the times and frequency to your needs.
# m h dom mon dow command
SHELL=/bin/bash
## Deprecated! We do not recommend to use the cron feature to schedule jobs
#*\/5 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT/tools/jobs.py project &>> /var/log/green-metrics-jobs.log
## We recommend to trigger the email job every 2-3 minutes
## You can trigger it more often, as it has a locking mechanism. The mechanism is however not fully parallel safe and email processing is not done in a transaction which might lead to race conditions if multiple connections to the DB in parallel try to set the DB lock.
*/2 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT/cron/jobs.py email-simple &>> /var/log/green-metrics-jobs.log
*/3 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT/cron/jobs.py email-report &>> /var/log/green-metrics-jobs.log
## If you only run daily or weekly projects this needs to only run once a day
## If you use the commit or tag feature we recommend every 15 minutes
15 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT/cron/watchlist.py schedule &>> /var/log/green-metrics-jobs.log
## If you use CarbonDB you must at least update and compress once a day.
## If you want more current data run this more often.
## Beware that this job is costly and can run up to multiple minutes if you have a large database
20 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT/cron/carbondb_compress.py &>> /var/log/green-metrics-jobs.log
9 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT/cron/carbondb_copy_over_and_remove_duplicates.py &>> /var/log/green-metrics-jobs.log
*/3 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT/cron/backfill_geo.py 2>&1 | logger -t gmt-cronjobs
*/10 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT/cron/backfill_carbon_intensity.py 2>&1 | logger -t gmt-cronjobs
## Maintenance and clear-up jobs
## Many come from the GMT helpers repo at https://github.com/green-coding-solutions/gmt-helpers
28 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT/cron/delete_expired_data.py 2>&1 | logger -t gmt-cronjobs
35 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT_HELPERS/cron/check_jobs_queue.py 3 2>&1 | logger -t gmt-cronjobs
30 0 * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT_HELPERS/nginx/send_log_report.py 2>&1 | logger -t gmt-cronjobs
22 7,16 * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT_HELPERS/db/check_consistency.py 2>&1 | logger -t gmt-cronjobs
*/5 * * * * PATH_TO_GMT/venv/bin/python3 PATH_TO_GMT_HELPERS/db/run_maintenance.py 2>&1 | logger -t gmt-cronjobsBe sure to create and give the green-metrics-jobs.log file write access rights.
Also be aware that our example for the cronjob assumes your crontab is using bash.
Consider adding SHELL=/bin/bash to your crontab if that is not the case.
Many files uses the Python faulthandler mechanism and will also report to STDERR in case of a segfault.
When running the cronjob we advice you to append all the output combined to a log file like shown above with the &>> operator.
Queuing / Locking
The Green Metrics Tool comes with an implemented queueing and locking mechanism. No two cron jobs can run at the same time and no extra guarding must be done.