-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openeo: automate workflow and job start
respecting maximum number of allowed concurrent jobs (2 for free tier usage) to do: figure out what advantages an paid suscription could have
- Loading branch information
Showing
9 changed files
with
178 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
data_dirs <- fs::dir_ls("vignettes/gee/current") | ||
remotes::install_github("kwb-r/kwb.satellite@dev") | ||
|
||
data <- stats::setNames(lapply(data_dirs[3], function(dir) { | ||
sat_dir <- "//medusa/projekte$/SUW_Department/Projects/AD4GD/Exchange/01_data/01_input/satellite_data/google-earth-engine" | ||
|
||
sat_dirs <- fs::dir_ls(sat_dir) | ||
|
||
sat_dat <- stats::setNames(lapply(data_dirs, function(dir) { | ||
kwb.satellite::import_rds(rds_dir = dir, flatten = TRUE) #%>% | ||
#dplyr::bind_rows() | ||
}), | ||
nm = basename(data_dirs[3])) | ||
|
||
length(tmp_list) | ||
|
||
tmp <- kwb.satellite::flatten_results(tmp_list) | ||
|
||
nm = basename(data_dirs)) | ||
|
||
kwb.satellite::flatten_results(tmp_list$`Bückwitzer See_point-on-surface_mean_scale-10m_2017-2023`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
openeo_con <- openeo::connect(host = "https://openeo.dataspace.copernicus.eu") | ||
openeo::login(openeo_con) | ||
|
||
test <- lapply(6:10, function(i) { | ||
kwb.satellite::openeo_get_data(lakes = lakes_bb_selected[i,]) | ||
}) | ||
|
||
job_ids <- sapply(1:5, function(i) test[[i]]$job$id) | ||
|
||
kwb.satellite::openeo_start_max_jobs(job_ids = job_ids) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#' Helper function OpenEO: check job status | ||
#' | ||
#' @param job_id job id | ||
#' @return status string of job | ||
#' @export | ||
#' @importFrom openeo describe_job | ||
#' | ||
check_job_status <- function(job_id) { | ||
job_info <- openeo::describe_job(job = job_id) | ||
return(job_info$status) | ||
} | ||
|
||
#' Helper function OpenEO: get number of active jobs | ||
#' | ||
#' @return number of active jobs | ||
#' @export | ||
#' | ||
#' @importFrom openeo list_jobs | ||
#' @importFrom tibble as_tibble | ||
#' @importFrom dplyr pull | ||
get_number_of_active_jobs <- function() { | ||
sum(openeo::list_jobs() %>% | ||
tibble::as_tibble() %>% | ||
dplyr::pull(status) %in% c("running", "queued")) | ||
} | ||
|
||
|
||
#' OpenEO: start maximum number of jobs | ||
#' | ||
#' @param job_ids character vector of job ids | ||
#' @param max_jobs maximum number of concurrent jobs (default: 2) | ||
#' @param check_interval check intervall in seconds if jobs are already finished | ||
#' @param debug print debug messages (default: TRUE) | ||
#' | ||
#' @return starts all jobs respecting the max_jobs limit | ||
#' @export | ||
#' @importFrom kwb.utils catAndRun | ||
openeo_start_max_jobs <- function(job_ids, max_jobs = 2, check_interval = 30, debug = TRUE) { | ||
idx <- 0 | ||
|
||
while(idx < length(job_ids)) { | ||
active_jobs <- get_number_of_active_jobs() | ||
|
||
# Starte so viele neue Jobs wie möglich | ||
while(active_jobs < max_jobs && idx < length(job_ids)) { | ||
idx <- idx + 1 | ||
job_status <- check_job_status(job_id = job_ids[idx]) | ||
|
||
if(job_status == "created") { | ||
kwb.utils::catAndRun(messageText = sprintf("Start job '%s' (%d/%d), active jobs: %d", | ||
job_ids[idx], | ||
idx, | ||
length(job_ids), | ||
active_jobs), | ||
expr = { | ||
openeo::start_job(job = job_ids[idx]) | ||
Sys.sleep(1) | ||
active_jobs <- get_number_of_active_jobs() | ||
|
||
Sys.sleep(1) # Kleine Pause, um Server nicht zu überlasten | ||
}, | ||
dbg = debug) | ||
} else if (job_status == "finished") { | ||
message(sprintf("Skipping job '%s'. It is already '%s'", | ||
job_ids[idx], | ||
job_status)) | ||
} else { | ||
message(sprintf("Skipping job '%s'. It is already '%s'", | ||
job_ids[idx], | ||
job_status)) | ||
} | ||
} | ||
|
||
if(active_jobs == max_jobs) { | ||
message(sprintf("We have to wait. There are already %d jobs 'running/queued' (%s)", | ||
active_jobs, | ||
Sys.time())) | ||
} | ||
|
||
# Wartezeit zwischen den Überprüfungen | ||
Sys.sleep(check_interval) | ||
|
||
# Überwachen und Anzahl der aktiven Jobs aktualisieren | ||
active_jobs <- get_number_of_active_jobs() | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.