-
Notifications
You must be signed in to change notification settings - Fork 0
/
ely.R
58 lines (38 loc) · 1.04 KB
/
ely.R
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
dir.create("var/logs", showWarnings = FALSE)
log_file_name <- sprintf("var/logs/update-%s.txt", Sys.Date())
log_file <- file(log_file_name, open = "wt")
sink(log_file)
sink(log_file, type = "message")
res <- tryCatch(
{
source("setup.R")
source("db-setup.R")
source("query.R")
source("transform-footprint.R")
source("ely-subsets.R")
source("ely-compute.R")
system2(
"rclone",
c(
"sync",
"\"var\"",
sprintf(
"\"default:%s-%s\"", Sys.getenv("OBJECT_STORE"), Sys.getenv("BRANCH")
)
)
)
message(sprintf("INFO [%s] Job complete", format(Sys.time())))
"true"
},
error = function(e) {
message(sprintf("ERROR [%s] %s", format(Sys.time()), e$message))
"false"
}
)
dir.create("var/status", showWarnings = FALSE)
cat(res, file = "var/status/success.txt")
cat(format(Sys.time(), usetz = TRUE), file = "var/status/last-update.txt")
DBI::dbDisconnect(con)
sink(type = "message")
sink()
file.copy(log_file_name, "var/logs/update-latest.txt", TRUE)