-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAPI_url_tracker.Rmd
More file actions
59 lines (51 loc) · 1.29 KB
/
API_url_tracker.Rmd
File metadata and controls
59 lines (51 loc) · 1.29 KB
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
---
title: "API URL tracker"
author: "Experiences Dashboard"
date: "2023-09-04"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(experiencesdashboard)
```
# Last rendered at `r round(Sys.time())`
## load the api job table from the database
```{r}
conn <- odbc::dbConnect(
drv = odbc::odbc(),
driver = Sys.getenv("odbc_driver"),
server = Sys.getenv("HOST_NAME"),
UID = Sys.getenv("DB_USER"),
PWD = Sys.getenv("MYSQL_PASSWORD"),
database = "TEXT_MINING",
Port = 3306
)
# connect to a pin board to save the prediction in case database writing fails.
board <- pins::board_connect()
# OR
# # Set board to Null if database writing is no longer an issue
# board = NULL
pending_jobs <- dplyr::tbl(
conn,
dbplyr::in_schema(
"TEXT_MINING",
"api_jobs"
)
) |>
dplyr::filter(status == "submitted") |>
dplyr::collect()
```
## GET THE PREDICTION
```{r track job}
Sys.sleep(2) # Sleep for 5 seconds to allow any pending tasks to start in the API.
# check the url of each submitted job and update the sentiment column of the main database table if the prediction is ready
if (nrow(pending_jobs) > 0) {
pending_jobs |>
apply(1, track_api_job,
conn = conn, write_db = TRUE,
board = board
)
} else {
paste("No pending job")
}
```