Skip to content

Commit

Permalink
Merge pull request #256 from saipavan10-git/improve_project_deletions…
Browse files Browse the repository at this point in the history
…_workflow

Add is_sequestered filter to sequestered_orphans
  • Loading branch information
pbchase authored Dec 4, 2024
2 parents 5c0ddb3 + bff5bf9 commit b9a01e1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion etl/delete_abandoned_projects.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ if(nrow(old_unpaid_invoices) > 0) {
unpaid_projects <- data.frame(pid = integer(), reason = character())
}

is_sequestered <- tbl(rc_conn, "redcap_projects") |>
left_join(tbl(rc_conn, "redcap_entity_project_ownership"), by = c("project_id" = "pid")) |>
filter(!is.na(completed_time) & sequestered == 1) |>
select(project_id) |>
collect() |>
pull(project_id)

sequestered_orphans <- tbl(rcc_billing_conn, "rcc_job_log") |>
filter(
script_name == "sequester_orphans" &
Expand All @@ -51,6 +58,8 @@ if (nrow(sequestered_orphans) > 0) {
select(project_ownership_sync_updates) |>
unnest(project_ownership_sync_updates) |>
select(pid) |>
# Only include projects that are currently sequestered
filter(pid %in% is_sequestered) |>
mutate(reason = "orphaned project")
} else {
orphaned_projects <- data.frame(pid = integer(), reason = character())
Expand All @@ -74,4 +83,3 @@ log_job_success(jsonlite::toJSON(activity_log))

dbDisconnect(rc_conn)
dbDisconnect(rcc_billing_conn)

0 comments on commit b9a01e1

Please sign in to comment.