From c0f36b49410bb24b4b432100203f4f111d2e2670 Mon Sep 17 00:00:00 2001 From: George Hickman Date: Tue, 7 Nov 2023 13:58:08 +0000 Subject: [PATCH] Set up cron tasks We want to configure our tasks with slightly more of an environment than a direct invocation gives us so this sets up a directory of shell scripts for each, currently used, cron invocation. In particular we want the GitHub and Slack ingestors to look for data from yesterday so we get a full days data and that needs access to `date`. --- app.json | 12 ++++++++++++ cron/daily.sh | 16 ++++++++++++++++ cron/weekly.sh | 8 ++++++++ 3 files changed, 36 insertions(+) create mode 100644 app.json create mode 100755 cron/daily.sh create mode 100755 cron/weekly.sh diff --git a/app.json b/app.json new file mode 100644 index 00000000..782da384 --- /dev/null +++ b/app.json @@ -0,0 +1,12 @@ +{ + "cron": [ + { + "command": "cron/daily.sh", + "schedule": "@daily" + }, + { + "command": "cron/weekly.sh", + "schedule": "@weekly" + } + ] +} diff --git a/cron/daily.sh b/cron/daily.sh new file mode 100755 index 00000000..11d1bddb --- /dev/null +++ b/cron/daily.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -euo pipefail + +# we want to get data for a full day, an easy way to do this is to always look +# at yesterday's data. +# the yesterday variable is here to make it easier for commands to do that, but +# there's no requirement that they do. +yesterday=$(date -d "1 day ago" '+%F') + +# PR throughput +python -m metrics github pr-throughput ebmdatalab "$yesterday" +python -m metrics github pr-throughput opensafely-core "$yesterday" + +# slack +python -m metrics slack tech-support "$yesterday" diff --git a/cron/weekly.sh b/cron/weekly.sh new file mode 100755 index 00000000..d0e9cf77 --- /dev/null +++ b/cron/weekly.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -euo pipefail + +yesterday=$(date -d "1 day ago" '+%F') + +python -m metrics github open-prs ebmdatalab "$yesterday" +python -m metrics github open-prs opensafely-core "$yesterday"