Skip to content

Commit

Permalink
Add additional parameters for custom property injection #125
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Jul 26, 2024
1 parent 94df102 commit 32d3651
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Version 1.4.0

## Added

* compute_result, create_job, update_job, create_service and update_service have an additional parameter to inject custom properties into the request (e.g., to set memory or CPU limits)

# Version 1.3.1

## Added
Expand Down
19 changes: 16 additions & 3 deletions R/jobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ setClass("Job")
#' @param as_stars logical to indicate if the data shall be interpreted as a stars object
#' @param format character or `FileFormat` specifying the File format for the output, if 'save_result' is not
#' set in the process then it will be added otherwise the value stated here will replace the original value.
#' @param additional Additional, non-standardized job settings to send to the back-end
#' @param con connected and authenticated openEO client (optional) otherwise [active_connection()]
#' is used.
#' @param ... additional parameters passed to jsonlite::toJSON() (like 'digits') or additional arguments that shall
Expand All @@ -72,7 +73,7 @@ setClass("Job")
#'
#' @importFrom methods as
#' @export
compute_result = function(graph, output_file = NULL, budget=NULL, plan=NULL, as_stars=FALSE, format = NULL, con=NULL, ...) {
compute_result = function(graph, output_file = NULL, budget=NULL, plan=NULL, as_stars=FALSE, format = NULL, additional = NULL, con=NULL, ...) {
tryCatch({
con = .assure_connection(con)
output = list()
Expand Down Expand Up @@ -151,6 +152,10 @@ compute_result = function(graph, output_file = NULL, budget=NULL, plan=NULL, as_
job$plan = plan
}

if (!is.null(additional)) {
job = c(job, additional)
}

is_tempfile = ifelse(length(output_file) == 0,TRUE,FALSE)

tag = "execute_sync"
Expand Down Expand Up @@ -213,13 +218,14 @@ compute_result = function(graph, output_file = NULL, budget=NULL, plan=NULL, as_
#' @param description Optional detailed information about a job
#' @param plan An optional execution plan offered by the back-end, determining how the job will be executed
#' @param budget An optional budget, which sets the maximum amount of credits to be used by the job
#' @param additional Additional, non-standardized job settings to send to the back-end
#' @param con connected and authenticated openEO client (optional) otherwise [active_connection()]
#' is used.
#' @param ... additional parameters passed to jsonlite::toJSON() (like 'digits')
#'
#' @return the id of the job
#' @export
create_job = function(graph = NULL, title = NULL, description = NULL, plan = NULL, budget = NULL, con=NULL, ...) {
create_job = function(graph = NULL, title = NULL, description = NULL, plan = NULL, budget = NULL, additional = NULL, con=NULL, ...) {
tryCatch({
con = .assure_connection(con)

Expand All @@ -233,6 +239,8 @@ create_job = function(graph = NULL, title = NULL, description = NULL, plan = NUL
job$plan = plan
if (!is.null(budget))
job$budget = budget
if (!is.null(additional))
job = c(job, additional)

# build an empty process
if (!is.null(graph)) {
Expand Down Expand Up @@ -320,12 +328,13 @@ start_job = function(job, log=FALSE, con=NULL) {
#' will return the results or a self defined [Process()]
#' @param plan replaces plan with the set value
#' @param budget replaces or sets the credits that can be spent at maximum
#' @param additional Additional, non-standardized job settings to send to the back-end
#' @param con connected and authenticated openEO client (optional) otherwise [active_connection()]
#' is used.
#' @param ... additional parameters passed to jsonlite::toJSON() (like 'digits')
#'
#' @export
update_job = function(id, title = NULL, description = NULL, process = NULL, plan = NULL, budget = NULL, con=NULL, ...) {
update_job = function(id, title = NULL, description = NULL, process = NULL, plan = NULL, budget = NULL, additional = NULL, con=NULL, ...) {
tryCatch({
con = .assure_connection(con)

Expand Down Expand Up @@ -362,6 +371,10 @@ update_job = function(id, title = NULL, description = NULL, process = NULL, plan
patch$budget = budget
}

if (!is.null(additional)) {
patch = c(patch, additional)
}

tag = "jobs_update"
res = con$request(tag = tag, parameters = list(id), authorized = TRUE, encodeType = "json", data = patch, ...)
message(paste("Job '", id, "' was successfully updated.", sep = ""))
Expand Down
14 changes: 12 additions & 2 deletions R/services.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ list_services = function(con=NULL) {
#' @param configuration a named list specifying the configuration parameter
#' @param plan character - the billing plan
#' @param budget numeric - the amount of credits that can be spent on this service
#' @param additional Additional, non-standardized service settings to send to the back-end
#' @param con connected and authenticated openEO client object (optional) otherwise [active_connection()]
#' is used.
#' @param ... additional parameters passed to jsonlite::toJSON() (like 'digits')
#'
#' @return Service object
#' @export
create_service = function(type, graph, title = NULL, description = NULL, enabled = NULL, configuration = NULL, plan = NULL, budget = NULL, con=NULL, ...) {
create_service = function(type, graph, title = NULL, description = NULL, enabled = NULL, configuration = NULL, plan = NULL, budget = NULL, additional = NULL, con=NULL, ...) {
tryCatch({
if (is.null(type)) {
stop("No type specified.")
Expand All @@ -68,6 +69,10 @@ create_service = function(type, graph, title = NULL, description = NULL, enabled
plan = plan,
budget = budget)

if (!is.null(additional)) {
service_request_object = c(service_request_object, additional)
}

# build an empty process
if (!is.null(graph)) {
process = Process$new(id=NA,description = NA,
Expand Down Expand Up @@ -118,14 +123,15 @@ create_service = function(type, graph, title = NULL, description = NULL, enabled
#' @param configuration a list of service creation configuration
#' @param plan character - the billing plan
#' @param budget numeric - the amount of credits that can be spent for this service
#' @param additional Additional, non-standardized service settings to send to the back-end
#' @param con connected and authorized openEO client object (optional) otherwise [active_connection()]
#' is used.
#' @param ... additional parameters passed to jsonlite::toJSON() (like 'digits')
#'
#' @return Service object
#'
#' @export
update_service = function(service, type = NULL, graph = NULL, title = NULL, description = NULL, enabled = NULL, configuration = NULL, plan = NULL, budget = NULL, con=NULL, ...) {
update_service = function(service, type = NULL, graph = NULL, title = NULL, description = NULL, enabled = NULL, configuration = NULL, plan = NULL, budget = NULL, additional = NULL, con=NULL, ...) {

tryCatch({
patch = list()
Expand Down Expand Up @@ -220,6 +226,10 @@ update_service = function(service, type = NULL, graph = NULL, title = NULL, desc
}
}

if (!is.null(additional)) {
patch = c(patch, additional)
}

tag = "services_update"
res = con$request(tag = tag, parameters = list(service), authorized = TRUE, encodeType = "json", data = patch, ...)
message(paste("Service '", service, "' was successfully updated.", sep = ""))
Expand Down

0 comments on commit 32d3651

Please sign in to comment.