-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_indices.R
76 lines (51 loc) · 1.33 KB
/
update_indices.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
dir.create("var/logs", showWarnings = FALSE)
log_file_name <- sprintf("var/logs/update-%s.txt", format(Sys.time(), "%F-%H"))
log_file <- file(log_file_name, open = "wt")
sink(log_file, split = TRUE)
sink(log_file, type = "message")
res <- withCallingHandlers(
tryCatch(
{
source("run_update.R", echo = FALSE)
"true"
},
error = function(e) {
writeLines(sprintf("ERROR [%s] %s", format(Sys.time()), e[["message"]]))
"false"
}
),
warning = function(w) {
writeLines(
sprintf(
"WARN [%s] %s",
format(Sys.time()),
gsub("\n|\r|\r\n", "; ", w[["message"]])
)
)
tryInvokeRestart("muffleWarning")
},
messsage = function(m) {
writeLines(
sprintf(
"WARN [%s] %s",
format(Sys.time()),
gsub("\n|\r|\r\n", "; ", m[["message"]])
)
)
tryInvokeRestart("muffleMessage")
}
)
sink(type = "message")
sink()
close(log_file)
httr::POST(
paste0("http://", Sys.getenv("APP_HOSTNAME"), ":", Sys.getenv("APP_PORT")),
path = "job-logs",
query = list(secret = Sys.getenv("JOB_SECRET")),
body = list(file = httr::upload_file(log_file_name))
)
httr::GET(
paste0("http://", Sys.getenv("APP_HOSTNAME"), ":", Sys.getenv("APP_PORT")),
path = "job",
query = list(status = res, secret = Sys.getenv("JOB_SECRET"))
)