-
Notifications
You must be signed in to change notification settings - Fork 20
/
notify-on-record-change
executable file
·33 lines (24 loc) · 1.19 KB
/
notify-on-record-change
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
set -euo pipefail
: "${SLACK_TOKEN:?The SLACK_TOKEN environment variable is required.}"
: "${SLACK_CHANNELS:?The SLACK_CHANNELS environment variable is required.}"
bin="$(dirname "$0")"
src="${1:?A source GenBank or GISAID ndjson file is required as the first argument.}"
dst="${2:?A destination GenBank or GISAID ndjson s3:// URL is required as the second argument.}"
source_name=${3:?A record source name is required as the third argument.}
# if the file is not already present, just exit
"$bin"/s3-object-exists "$dst" || exit 0
src_record_count="$(wc -l < "$src")"
dst_record_count="$(wc -l < <(aws s3 cp --no-progress "$dst" - | xz -T0 -dcfq))"
added_records="$(( src_record_count - dst_record_count ))"
printf "%'4d %s\n" "$src_record_count" "$src"
printf "%'4d %s\n" "$dst_record_count" "$dst"
printf "%'4d added records\n" "$added_records"
if [[ $added_records -gt 0 ]]; then
echo "Notifying Slack about added records (n=$added_records)"
"$bin"/notify-slack "📈 New nCoV records (n=$added_records) found on $source_name."
elif [[ $added_records -lt 0 ]]; then
echo "New file has fewer records‽"
else
echo "Files have the same number of records, skipping notification"
fi