Skip to content

Commit b0e621c

Browse files
committed
added telemetry functions
1 parent 3d6ce8f commit b0e621c

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Imports:
3939
stringr,
4040
segmented,
4141
LambertW,
42-
rlang
42+
rlang,
43+
httr2
4344
Suggests:
4445
knitr,
4546
devtools,

R/kinfitr_telemetry.R

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
library(httr2)
2+
3+
get_url = "http://127.0.0.1:8000/check/kinfitr/"
4+
post_url = "http://127.0.0.1:8000/kinfitr/"
5+
6+
get_telemetry <- function(url = get_url, number_of_records=0) {
7+
# checks to see what's been posted to the url endpoint, should return location,
8+
# and any other data that gets put there with send_telemetry
9+
req <- request(paste(url, as.character(number_of_records), sep=""))
10+
req |> req_headers("Accept" = "application/json")
11+
req |> req_retry(max_tries = 3)
12+
req |> req_timeout(3)
13+
response <- req_perform(req)
14+
return(resp_body_json(response))
15+
}
16+
17+
send_telemetry <- function(telemetry_json_data, url = post_url) {
18+
# Accepts a list of telemetry data (worth transmitting of course) and converts
19+
# it such that it can be sent as a json to the endpoint.
20+
#
21+
# Additionally, checks to to see if environment variable KINFITR_NO_TRACK is set
22+
# if it is, this does nothing.
23+
24+
no_track <- Sys.getenv("KINFITR_NO_TRACK")
25+
26+
if (tolower(no_track) == "true") {
27+
return(NULL)
28+
} else {
29+
try({req <- request(url)
30+
req |> req_retry(max_tries = 3)
31+
req |> req_timeout(3)
32+
response <- req |>
33+
req_body_json(data = telemetry_json_data) |>
34+
req_perform()
35+
return_values <- list(status_code = response$status_code)
36+
return(return_values)},
37+
silent = TRUE)
38+
}
39+
}
40+
41+
#list_to_send <- list("part1" = "one", "part2" = "new")
42+
#end_telemetry(list_to_send)
43+

0 commit comments

Comments
 (0)