logic for missing query states

This commit is contained in:
Carlos R. Mercado 2024-01-09 15:12:30 -05:00
parent e3f7f56c9e
commit c7f4656df1
7 changed files with 39 additions and 5 deletions

0
r/shroomDK/.Rhistory Normal file
View File

View File

@ -1,7 +1,7 @@
Package: shroomDK
Type: Package
Title: Accessing the Flipside Crypto ShroomDK API
Version: 0.2.2
Version: 0.3.0
Author: Carlos Mercado
Maintainer: Carlos Mercado <carlos.mercado@flipsidecrypto.com>
Description: Programmatic access to Flipside Crypto data via the Compass RPC API: <https://api-docs.flipsidecrypto.xyz/>. As simple as auto_paginate_query() but with core functions as needed for troubleshooting. Note, 0.1.1 support deprecated 2023-05-31.

View File

@ -46,7 +46,19 @@ auto_paginate_query <- function(query, api_key,
query_status <- get_query_status(query_run_id = query_run_id, api_key = api_key, api_url = api_url)
query_state <- query_status$result$queryRun$state
if(query_state == "QUERY_STATE_SUCCESS"){
failed_to_get_a_state = 0
if(failed_to_get_a_state > 2){
warning("Query has failed state more than twice, consider cancel_query(), exiting now")
stop("Exited due to 3+ Failed States")
}
if(length(query_state) == 0){
warning("Query failed to return a state, trying again")
Sys.sleep(5)
failed_to_get_a_state = failed_to_get_a_state + 1
} else {
if(query_state == "QUERY_STATE_SUCCESS"){
status_check_done <- TRUE
result_num_rows <- query_status$result$queryRun$rowCount
result_file_size <- as.numeric(query_status$result$queryRun$totalSize)
@ -64,6 +76,7 @@ auto_paginate_query <- function(query, api_key,
)
Sys.sleep(10)
}
}
}
if(is.null(page_count)){

View File

@ -63,7 +63,7 @@ create_query_token <- function(query, api_key,
"sql" = query,
"tags" = list(
"sdk_package" = "R",
"sdk_version" = "0.2.1",
"sdk_version" = "0.3.0",
"sdk_language" = "R"
),
"dataSource" = data_source,

View File

@ -36,8 +36,19 @@ get_query_from_token <- function(query_run_id, api_key,
while (!status_check_done) {
query_status <- get_query_status(query_run_id = query_run_id, api_key = api_key, api_url = api_url)
query_state <- query_status$result$queryRun$state
failed_to_get_a_state = 0
if(query_state == "QUERY_STATE_SUCCESS"){
if(failed_to_get_a_state > 2){
warning("Query has failed state more than twice, consider cancel_query(), exiting now")
stop("Exited due to 3+ Failed States")
}
if(length(query_state) == 0){
warning("Query failed to return a state, trying again")
Sys.sleep(5)
failed_to_get_a_state = failed_to_get_a_state + 1
} else {
if(query_state == "QUERY_STATE_SUCCESS"){
status_check_done <- TRUE
next()
} else if(query_state == "QUERY_STATE_FAILED"){
@ -47,10 +58,20 @@ get_query_from_token <- function(query_run_id, api_key,
status_check_done <- TRUE
stop("This query was canceled, typically by cancel_query()")
} else if(query_state != "QUERY_STATE_SUCCESS"){
warning("Query in process, checking again in 5 seconds, use cancel_query() if needed.")
warning(
paste0("Query in process, checking again in 10 seconds.",
"To cancel use: cancel_query() with your ID: \n", query_run_id)
)
Sys.sleep(5)
} else if(query_state != "QUERY_STATE_SUCCESS"){
warning(
paste0("Query in process, checking again in 10 seconds.",
"To cancel use: cancel_query() with your ID: \n", query_run_id)
)
Sys.sleep(10)
}
}
}
headers = c(
"Content-Type" = 'application/json',

Binary file not shown.

BIN
r/shroomDK_0.3.0.tar.gz Normal file

Binary file not shown.