-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathupdate-stats
executable file
·38 lines (26 loc) · 1.24 KB
/
update-stats
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
34
35
36
37
38
#!/bin/bash
# Usage:
# update-stats releases/clojars-web-current.jar [20200120]
set -e
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "$dir/set_default_java_opts.bash"
clojars_jar=$1
date=$2
if [ -z "$date" ]; then
date=$(date --date='1 day ago' +%Y%m%d)
fi
mkdir -p tmp
cdn_logfile=tmp/cdn-access-yesterday.log
# generate the combined cdn stats first
"$dir"/combine-cdn-logs "$clojars_jar" "$cdn_logfile" "$date"
S3_STATS_BUCKET=clojars-stats-production
downloads_date=tmp/downloads-$date.edn
downloads_all_old=tmp/all-old.edn
downloads_all_new=tmp/all-new.edn
# grab the latest all.edn from s3
aws s3 cp "s3://${S3_STATS_BUCKET}/all.edn" "$downloads_all_old"
cat "$cdn_logfile" | java "${JAVA_OPTS[@]}" -cp "$clojars_jar" clojure.main -m clojars.tools.process-stats > "$downloads_date"
java "${JAVA_OPTS[@]}" -cp "$clojars_jar" clojure.main -m clojars.tools.merge-stats "$downloads_all_old" "$downloads_date" > "$downloads_all_new"
# upload the new stats to the s3 bucket
aws s3 cp --no-progress --content-type 'application/edn' --acl public-read "$downloads_date" "s3://${S3_STATS_BUCKET}/"
aws s3 cp --no-progress --content-type 'application/edn' --acl public-read "$downloads_all_new" "s3://${S3_STATS_BUCKET}/all.edn"