Handlers

class DANE.handlers.ESHandler(config, queue=None)
assignTask(task, document_id)

Assign a task to a document and run it.

Parameters:
  • task (DANE.Task) – the task to assign
  • document_id (int) – id of the document this task belongs to
Returns:

task_id

Return type:

int

assignTaskToMany(task, document_ids)

Assign a task to a document and run it.

Parameters:
  • task (DANE.Task) – the task to assign
  • document_id ([int]) – list of ids of the documents to assign this to
Returns:

task_ids

Return type:

[int]

callback(task_id, response)

Function that is called once a task gives back a response.

This updates the state and response of the task in the database, and then tries to run the other tasks assigned to the document.

Parameters:
  • task_id (int) – The id of a task
  • response (dict) – Task response, should contain at least the state and a message
deleteDocument(document)

Delete a document and its underlying tasks from the database

Parameters:document (DANE.Document) – The document
deleteResult(result)

Delete a result

Parameters:result (DANE.Result) – The result to delete
Returns:bool
deleteTask(task)

Delete a task.

Parameters:task (DANE.Task) – the task to delete
Returns:bool
documentFromDocumentId(document_id)

Construct and return a DANE.Document given a document_id

Parameters:document_id (int) – The id for the document
Returns:The document
Return type:DANE.Document
documentFromTaskId(task_id)

Construct and return a DANE.Document given a task_id

Parameters:task_id (int) – The id of a task
Returns:The document
Return type:DANE.Document
getAssignedTasks(document_id, task_key=None)

Retrieve tasks assigned to a document. Accepts an optional task_key to filter for a specific type of tasks.

Parameters:
  • document_id – document to of interest
  • task_key (string, optional) – Key of task type to filter for
Returns:

list of dicts with task ids, keys, and states.

getTaskKey(task_id)

Retrieve task_key for a given task_id

Parameters:task_id (int) – id of the task
Returns:task_key
Return type:str
getTaskState(task_id)

Retrieve state for a given task_id

Parameters:task_id (int) – id of the task
Returns:task_state
Return type:int
getUnfinished(only_runnable=False)

Returns tasks which are not finished, i.e., tasks that dont have state 200

Parameters:only_runnable – Return only tasks that can be run()
Returns:ids of found tasks
Return type:dict
registerDocument(document)

Register a document in the database

Parameters:document (DANE.Document) – The document
Returns:document_id
Return type:int
registerDocuments(documents)

Register list of documents in the database

Parameters:document (DANE.Document) – The document
Returns:two lists with successfully and failed documents, as tuple
registerResult(result, task_id)

Save a result for a task

Parameters:
  • result (DANE.Result) – The result
  • task_id – id of the task that generated this result
Returns:

self

resultFromResultId(result_id)

Construct and return a DANE.Result given a result_id

Parameters:result_id (int) – The id of a result
Returns:The result
Return type:DANE.Result
retry(task_id, force=False)

Retry the task with this id.

Attempts to run a task which previously might have crashed. Defaults to skipping tasks with state 200, or 102, unless Force is specified, then it should rerun regardless of previous state.

Parameters:
  • task_id (int) – The id of a task
  • force (bool, optional) – Force task to rerun regardless of previous state
run(task_id)

Run the task with this id, and change its task state to 102.

Running a task involves submitting it to a queue, so results might only be available much later. Expects a task to have state 201, and it may retry tasks with state 502 or 503.

Parameters:task_id (int) – The id of a task
search(target_id, creator_id, page=1)

Returns documents matching target_id and creator_id

Parameters:
  • target_id – The id of the target
  • creator_id – The id of the creator
Returns:

list of found documents

searchResult(document_id, task_key)

Search for a result of a task with task_key applied to a specific document

Parameters:
  • document_id – id of the document the task should be applied to
  • task_key – key of the task that was applied
Returns:

List of initialised DANE.Result

taskFromTaskId(task_id)

Retrieve task for a given task_id

Parameters:task_id (int) – id of the task
Returns:the task, or error if it doesnt exist
Return type:DANE.Task
updateTaskState(task_id, state, message)

Update the state, message, and last updated of a task.

Parameters:
  • task_id (int, required) – The id of a task
  • state (int, required) – The new task state
  • message (string, required) – The new task message