Skip to content

Commit

Permalink
Database update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry-DJPR authored Aug 25, 2023
1 parent 635fb24 commit b03de4e
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions data-raw/create_dash_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,40 @@ if(length(hash_matches) > 0){





# Add data to database
mapply(
FUN = pool::dbWriteTable,
conn = list(con),
name = names(out),
value = out,
overwrite = TRUE
# Error handling
trycatch(
{
# Add data to database
mapply(
FUN = pool::dbWriteTable,
conn = list(con),
name = names(out),
value = out,
overwrite = TRUE
)

# Update hashes
if(length(out) > 0){

new_hashes <- data.frame(
name = names(out),
timestamp = Sys.time(),
rlanghash = sapply(out, rlang::hash)
)

pool::dbAppendTable(con, "tablevalidation", new_hashes)
}

# Clear environment and disconnect
pool::poolClose(con)

},
error = function(e) warning(e)
)




# Update hashes
if(length(out) > 0){

new_hashes <- data.frame(
name = names(out),
timestamp = Sys.time(),
rlanghash = sapply(out, rlang::hash)
)

pool::dbAppendTable(con, "tablevalidation", new_hashes)
}




# Clear environment and disconnect
pool::poolClose(con)
# Clear environment
rm(list = ls())


Expand Down

0 comments on commit b03de4e

Please sign in to comment.