weaver.wps_restapi.jobs.utils

Module Contents

weaver.wps_restapi.jobs.utils.MultiPartFieldsParamsType[source]
weaver.wps_restapi.jobs.utils.LOGGER[source]
weaver.wps_restapi.jobs.utils.get_job(request: weaver.typedefs.PyramidRequest) weaver.datatype.Job[source]

Obtain a Job from request parameters.

Changed in version 4.20: When looking for Job that refers to a local Process, allow implicit resolution of the unspecified version portion to automatically resolve the identifier. Consider that validation of the expected Process for this Job is “good enough”, since the specific ID is not actually required to obtain the Job (could be queried by ID only on the /jobs/{jobId} endpoint. If the version is provided though (either query parameter or tagged representation), the validation will ensure that it matches explicitly.

Parameters:

request – Request with path and query parameters to retrieve the desired job.

Returns:

Job information if found.

Raises:

HTTPNotFound – with JSON body details on missing/non-matching job, process, provider IDs.

Obtains a list of all relevant links for the corresponding job listing defined by query parameter filters.

Raises:

IndexError – if the paging values are out of bounds compared to available total Job matching search.

weaver.wps_restapi.jobs.utils.get_job_io_schema_query(schema: str | None, strict: bool = True, default: weaver.processes.constants.JobInputsOutputsSchemaType = None) weaver.processes.constants.JobInputsOutputsSchemaType[source]
weaver.wps_restapi.jobs.utils.get_job_status_schema(request: weaver.typedefs.AnyRequestType) Tuple[weaver.processes.constants.JobStatusSchemaType, weaver.typedefs.HeadersType][source]

Identifies if a Job status response schema applies for the request.

Convert a result definition as value into the corresponding reference for output transmission.

See also

RFC 8288: HTTP Link header specification.

weaver.wps_restapi.jobs.utils.get_results(job: weaver.datatype.Job, container: weaver.typedefs.AnySettingsContainer, value_key: str | None = None, schema: weaver.processes.constants.JobInputsOutputsSchemaType | None = JobInputsOutputsSchema.OLD, link_references: bool = False) Tuple[weaver.typedefs.ExecutionResults, weaver.typedefs.HeadersTupleType][source]

Obtains the job results with extended full WPS output URL as applicable and according to configuration settings.

Parameters:
  • job – job from which to retrieve results.

  • container – any container giving access to instance settings (to resolve reference output location).

  • value_key – If not specified, the returned values will have the appropriate data/href key according to the content. Otherwise, all values will have the specified key.

  • schema – Selects which schema to employ for representing the output results (listing or mapping).

  • link_references – If enabled, an output that was requested by reference instead of by value will be returned as Link header.

Returns:

Tuple with:
  • List or mapping of all outputs each with minimally an ID and value under the requested key.

  • List of Link headers for reference outputs when requested. Empty otherwise.

weaver.wps_restapi.jobs.utils.get_job_return(job: weaver.datatype.Job | None = None, body: weaver.typedefs.JSON | None = None, headers: weaver.typedefs.AnyHeadersContainer | None = None) Tuple[weaver.execute.AnyExecuteResponse, weaver.execute.AnyExecuteReturnPreference][source]

Obtain the Job result representation based on the resolution order of preferences and request parameters.

Body and header parameters are considered first, in case they provide ‘overrides’ for the active request. Then, if the job was already parsed from the original request, and contains pre-resolved return, this format is employed. When doing the initial parsing, job=None MUST be used.

weaver.wps_restapi.jobs.utils.get_job_output_transmission(job: weaver.datatype.Job, output_id: str, is_reference: bool) Tuple[weaver.execute.AnyExecuteTransmissionMode, weaver.typedefs.JobValueFormat | None][source]

Obtain the requested Job output transmissionMode and format.

weaver.wps_restapi.jobs.utils.get_job_results_response(job: weaver.datatype.Job, *, container: weaver.typedefs.AnySettingsContainer, request_headers: weaver.typedefs.AnyHeadersContainer | None = None, response_headers: weaver.typedefs.AnyHeadersContainer | None = None, results_headers: weaver.typedefs.AnyHeadersContainer | None = None, results_contents: weaver.typedefs.JSON | None = None) weaver.typedefs.AnyResponseType[source]

Generates the OGC compliant Job results response according to submitted execution parameters.

Parameters that impact the format of the response are:
  • Body parameter outputs with the amount of requested outputs to be returned.

  • Body parameter response: raw|document for content representation.

  • Body parameter transmissionMode: value|reference per output.

  • Header parameter Prefer: return=representation|minimal for content representation.

  • Overrides, for any of the previous parameters, allowing request of an alternate representation.

Resolution order/priority:

  1. override_contents

  2. override_headers

  3. job definitions

The logic of the resolution order is that any body parameters resolving to an equivalent information provided by header parameters will be more important, since Prefer are soft requirements, whereas body parameters are hard requirements. The parameters stored in the job are defined during Job submission, which become the “default” results representation if requested as is. If further parameters are provided to override during the results request, they modify the “default” results representation. In this case, an header provided in the results request overrides the body parameters from the original Job, since their results request context is “closer” than the ones at the time of the Job submission.

Parameters:
  • job – Job for which to generate the results response, which contains the originally submitted parameters.

  • container – Application settings.

  • request_headers – Original headers submitted to the request that leads to this response.

  • response_headers – Additional headers to provide in the response.

  • results_headers – Headers that override originally submitted job parameters when requesting results.

  • results_contents – Body contents that override originally submitted job parameters when requesting results.

weaver.wps_restapi.jobs.utils.generate_or_resolve_result(job: weaver.datatype.Job, result: weaver.typedefs.ExecutionResultObject, result_id: str, output_id: str, output_mode: weaver.execute.AnyExecuteTransmissionMode, output_format: weaver.typedefs.JobValueFormat | None, settings: weaver.typedefs.SettingsType) Tuple[weaver.typedefs.HeadersType, weaver.typedefs.AnyDataStream | None][source]

Obtains the local file path and the corresponding URL reference for a given result, generating it as needed.

Parameters:
  • job – Job with results details.

  • result – The specific output value or reference (could be an item index within an array of a given output).

  • result_id – Specific identifier of the result, including any array index as applicable.

  • output_id – Generic identifier of the output containing the result.

  • output_mode – Desired output transmission mode.

  • output_format – Desired output transmission format, with minimally the Media-Type.

  • settings – Application settings to resolve locations.

Returns:

Resolved headers and data (as applicable) for the result. If only returned by reference, None data is returned. An empty-data contents would be an empty string. Therefore, the explicit check of None is important to identify a by-reference result.

weaver.wps_restapi.jobs.utils.resolve_result_json_literal(result: weaver.typedefs.ExecutionResultValue, output_format: weaver.typedefs.JobValueFormat | None, content_type: str | None = None, content_encoding: str | None = None) weaver.typedefs.ExecutionResultValue[source]

Generates a JSON literal string or object representation according to requested format and result contents.

If not a value structure, the result is returned unmodified. If no output format is provided, or that the extracted result Media-Type does not correspond to a JSON value, the result is also unmodified. Otherwise, string/object representation is resolved according to the relevant Media-Type.

Parameters:
  • result – Container with nested data.

  • output_format – Desired output transmission format, with minimally the Media-Type.

  • content_type – Explicit Media-Type to employ instead of an embedded mediaType result property.

  • content_encoding – Explicit data encoding to employ instead of an embedded encoding result property.

Returns:

Converted JSON data or the original result as applicable.

Generates Link headers for all specified result references and adds them to the specified header container.

weaver.wps_restapi.jobs.utils.get_job_results_single(job: weaver.datatype.Job, result: weaver.typedefs.ExecutionResultObject, output_id: str, output_format: weaver.typedefs.JobValueFormat | None, headers: weaver.typedefs.AnyHeadersContainer, *, settings: weaver.typedefs.AnySettingsContainer) pyramid.httpexceptions.HTTPOk | pyramid.httpexceptions.HTTPNoContent[source]

Generates a single result response according to specified or resolved output transmission and format.

Parameters:
  • job – Job definition to obtain relevant path resolution.

  • result – Result to be represented.

  • output_id – Identifier of the corresponding result output.

  • output_format – Desired output format for convertion, as applicable.

  • headers – Additional headers to include in the response.

  • settings – Application settings to resolve locations.

Returns:

weaver.wps_restapi.jobs.utils.get_job_results_document(job: weaver.datatype.Job, results: weaver.typedefs.ExecutionResults, *, settings: Any) weaver.typedefs.ExecutionResults[source]

Generates the Job results document response from available or requested outputs with necessary conversions.

Removes nested literal value definitions if qualified value representation is not needed. Qualified value representation is not needed if no other field than value is provided with the literal data, or when the specified Media-Type is simply the plain text default for data literals. The simplification is applied for both literals on their own and nested array of literals. However, when processing an array, the qualified value representation is preserved if any of the items requires the explicit mention of another Media-Type than plain text, to return a consistent structure.

Uses the job definition and submitted headers

Warning

This function assumes that schema deserialization was applied beforehand. Therefore, it will not attempt matching every possible combination of the results representation.

weaver.wps_restapi.jobs.utils.get_job_results_multipart(job: weaver.datatype.Job, results: weaver.typedefs.ExecutionResults, *, headers: Any, settings: weaver.typedefs.AnyHeadersContainer) pyramid.httpexceptions.HTTPOk[source]

Generates the Job results multipart response from available or requested outputs with necessary conversions.

See also

Parameters:
  • job – Job definition with potential metadata about requested outputs.

  • results – Pre-filtered and pre-processed results in a normalized format structure.

  • headers – Additional headers to include in the response.

  • settings – Application settings to resolve locations.

weaver.wps_restapi.jobs.utils.get_job_submission_response(body: weaver.typedefs.JSON, headers: weaver.typedefs.AnyHeadersContainer) weaver.typedefs.HTTPValid[source]

Generates the response contents returned by Job submission process.

If Job already finished processing within requested Prefer: wait=X seconds delay (and if allowed by the Process jobControlOptions), return the successful status immediately instead of created status.

If the status is not successful, return the failed Job status response.

Otherwise, return the status monitoring location of the created Job to be monitored asynchronously.

weaver.wps_restapi.jobs.utils.validate_service_process(request: weaver.typedefs.PyramidRequest) Tuple[str | None, str | None][source]

Verifies that any Provider or Process specified by path or query are valid.

Raises:

HTTPException – Relevant HTTP error with details if validation failed.

Returns:

Validated and existing service and process if specified.

weaver.wps_restapi.jobs.utils.raise_job_bad_status_locked(job: weaver.datatype.Job, container: weaver.typedefs.AnySettingsContainer | None = None) None[source]

Raise the appropriate message for Job unable to be modified.

weaver.wps_restapi.jobs.utils.raise_job_bad_status_success(job: weaver.datatype.Job, container: weaver.typedefs.AnySettingsContainer | None = None) None[source]

Raise the appropriate message for Job not ready or unable to retrieve output results due to status.

weaver.wps_restapi.jobs.utils.raise_job_dismissed(job: weaver.datatype.Job, container: weaver.typedefs.AnySettingsContainer | None = None) None[source]

Raise the appropriate messages for dismissed Job status.

weaver.wps_restapi.jobs.utils.dismiss_job_task(job: weaver.datatype.Job, container: weaver.typedefs.AnySettingsContainer) weaver.datatype.Job[source]

Cancels any pending or running Celery task and removes completed job artifacts.

Note

The Job object itself is not deleted, only its artifacts. Therefore, its inputs, outputs, logs, exceptions, etc. are still available in the database, but corresponding files that would be exposed by weaver.wps_output configurations are removed.

Parameters:
  • job – Job to cancel or cleanup.

  • container – Application settings.

Returns:

Updated and dismissed job.

weaver.wps_restapi.jobs.utils.get_job_prov_response(request: weaver.typedefs.PyramidRequest) weaver.typedefs.AnyResponseType[source]

Retrieve specific Provenance contents of a Job based on the request.

The specific request path is redirected to the relevant command from cwlprov. If applicable, request Media-Type specifiers are considered to return alternate representations.