Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement API support to /jobs endpoint #26

Closed
rolfsimoes opened this issue Apr 5, 2024 · 3 comments · Fixed by #27
Closed

Implement API support to /jobs endpoint #26

rolfsimoes opened this issue Apr 5, 2024 · 3 comments · Fixed by #27
Assignees

Comments

@rolfsimoes
Copy link
Collaborator

rolfsimoes commented Apr 5, 2024

Links to #21, #18

Implement api_jobs() function to support /jobs endpoint.
Please, see OpenEO documentation on jobs endpoint.

@rolfsimoes
Copy link
Collaborator Author

rolfsimoes commented Apr 12, 2024

Jobs must be run in new R process. We can start a new process using the package callr. The package provides basic functionality to interact with R process and can be used to build some dynamic fields of jobs endpoint response.

# Get all needed parameter to create a new API object
params <- api_params(api)

# params content:
# list(id = ..., title, description, backend_version, api_version, processes_file, collections)

# Create a new api object based on input parameters (to be run in **new process** side):
api <- api_from_params(params)
# This should be an openeocraft function
api_new_job <- function(api, req, res) {
  user <- user_session(req)
  p <- req$body
  if ("process" %in% names(p))
    p <- p$process
  job <- job_create(api, p, user)
  job_save(job) # user is a variable that identifies the current user
  return(job)
}
# Possible implementation of `job_start()`
job_start <- function(job) {
  callr::r(function() {
    api <- job_api(job)
    p <- job_pgraph(job)
    result <- run_pgraph(api, p)
    job_save_result(job, result) # user workspace
  })
}

The endpoint implementation (plumber.R) could be:

#* @post /jobs
function(req, res) {
  job <- api_new_job(api, req, res)
  job_start(job)
  return(job_info(job))
}

#* @get /jobs/<job_id>
function(req, res, job_id) {
  job <- job_read(api, res, req, job_id)
  return(job_info(job))
}

#* @delete /jobs/<job_id>
function(req, res, job_id) {
  job <- job_delete(api, res, req, job_id) # inside job_delete: user <- user_session(req)
  return(job_info(job))
}

Possible new functions:

  • job_save_result()
  • job_api()
  • job_save()
  • job_read()
  • job_delete()
  • job_create()
  • job_api_params()
  • job_start()
  • job_info()

This issue depends on #18 to be able to define workspace.

@rolfsimoes
Copy link
Collaborator Author

image

@PondiB
Copy link
Collaborator

PondiB commented Apr 23, 2024

Possible new functions:

  • job_save_result()
  • job_api()
  • job_save()
  • job_read()
  • job_delete()
  • job_create()
  • job_api_params()
  • job_start()
  • job_info()
  • job_update()
  • job_get_results()
  • jobs_list_all()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants