Sections
You are here: Home » Development » API » API 1.1 - archived version » Task

Task

Asynchronous jobs are handled via an intermediate Task resource. A resource, submitting an asynchronous job should return the URI of the task.

REST operations

Description Method URI Parameters Result Status codes
Get a list of all available tasks GET /task ?query=task status as in opentox.owl
List of URIs  text/uri-list
RDF representation  application/rdf+xml
200,503,401
Get the representation of a running task GET /task/{id} -
Task representation in application/rdf+xml
200,201,202,404,503,401
Delete (cancel) a task DELETE /task/{id}

200, 404, 503,401

Background

Provides access to the asynchronous jobs running in the system. Access should be restricted (to be specified in the authorization API).

  • A resource that creates an asynchronous task (e.g. large dataset upload, model creation, model prediction) should return HTTP status code 202 and task representation (URI(s) if Accept:text/uri-list , or RDF/XML if Accept:application/rdf+xml) in the response body, as specified by the HTTP protocol.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
10.2.3 202 Accepted
 The 202 response is intentionally non-committal. Its purpose is to allow a server to accept a request for some other 
 process (perhaps a batch-oriented process that is only run once per day) without requiring that the user agent's connection
 to the server persist until the process is completed. The entity returned with this response SHOULD include an indication of
 the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the
 request to be fulfilled.
  • If GET /task/{id} is requested and the task is not completed, the task resource returns status code 202 (accepted, processing has not been completed)  and task representation (URI(s) if Accept:text/uri-list , or RDF/XML if application/rdf+xml) in the response body, as specified by the HTTP protocol.
  • If GET /task/{id} is requested and the task is completed:
  1. if another task resumes the job, the resource returns status code 201 and the URL of the new task in the body, or task RDF/XML representation with ot:resultURI property set to the new task URI, if "Accept:application/rdf+xml".
  2. if the job is done and the final result should be returned, the resource returns status code 200 and the URL(s) of the result in the body, or task RDF/XML representation with ot:resultURI property set to the result URI, if "Accept:application/rdf+xml".

 

RDF representation

 

The asynchronous task is represented by OpenTox Task object, as defined in OpenTox ontology http://www.opentox.org/api/1.1/opentox.owl#Task

 

A task object has the following properties:

  • dc:date - specifies when the task has been created; of type xsd:dateTime ;
  • dc:creator - specifying the URI of the resource, where the task has been created,  of type xsd:anyURI ;
  • dc:title - human readable title of the task, of type xsd:string;
  • dc:description (optional , eventually might be used for error reporting ?)
  • ot:hasStatus  - one of "Cancelled", "Completed", "Running", "Error"
  • ot:percentageCompleted - of type xsd:float
  • ot:resultURI - specifies the URI(s) of the newly created resource, of type xsd:anyURI ; present only if status is "Completed"

 

Incompleted task (N3 notation)

@prefix ot:      <http://www.opentox.org/api/1.1#> .
@prefix dc:      <http://purl.org/dc/elements/1.1/> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .


[]    a       ot:Task ;
      dc:date "1269258300474"^^xsd:dateTime ;
      dc:creator "http://host/model/149389"^^xsd:anyURI ;
      dc:title "Apply Classification: Decision tree J48 to http://host/dataset/1"^^xsd:string ;
      ot:hasStatus "Running"^^xsd:string ;
      ot:percentageCompleted
              "50.0"^^xsd:float .


Completed task  (N3 notation)

@prefix ot:      <http://www.opentox.org/api/1.1#> .
@prefix dc:      <http://purl.org/dc/elements/1.1/> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .


[]    a       ot:Task ;
      dc:date "1269258300474"^^xsd:dateTime ;
      dc:creator "http://host/model/149389"^^xsd:anyURI ;
      dc:title "Apply Classification: Decision tree J48 to http://host/dataset/1"^^xsd:string ;
      ot:hasStatus "Completed"^^xsd:string ;
      ot:resultURI "http://host/dataset/666"^^xsd:anyURI ;
      ot:percentageCompleted
              "100.0"^^xsd:float .


 

HTTP status codesΒΆ

Interpretation Nr Name
Success 200 OK The task is completed, the representation contains URI of the result
Pointer to other Task
201
Task has finished, another Task resumes the Job (URI is specified in result)
Processing 202 Accepted, processing has not completed
task_id is wrong 400 Bad Request
Not Authorized 401 Not Authorized
Task for specific id not found 404 Not Found
Error 500 Internal server error
Service not available 503 Service unavailable

 

Document Actions

Task history

Posted by Surajit Ray at Feb 23, 2010 06:16 PM
Do we need some mechanism to get a history of a long running task? It might be beneficial to see which internal step might be failing ...

Readings

Posted by Jeliazkova Nina at Mar 19, 2010 01:11 PM