Execution
  • Dark
    Light
  • PDF

Execution

  • Dark
    Light
  • PDF

An execution is a run of the function on a service with specific inputs. One may use the execution to monitor the run, and retrieve the function's output.
execution.PNG

Execution Input

The execution input is the same input the function requires. See Class Functions Input types for reference.
The input will be provided to the method the execution invokes.

For example:

dl.FunctionIO(name='model_filename', type=dl.PackageInputType.JSON),
dl.FunctionIO(name='dataset', type=dl.PackageInputType.DATASET),
dl.FunctionIO(name='item', type=dl.PackageInputType.ITEM)
#When executing:
execution = service.execute(execution_input=dl.FunctionIO(name='item', value='item-id',type=dl.PackageInputType.ITEM), project_id='project-id', function_name='function-name')
  • The input of Dataloop type ( item, dataset, annotation, etc) should be passed with an ID of the corresponding entity.
  • The input of type Json can have any JSON serializable value and will provide it as is to the method.

Execution Status

execution.statusLog holds an array of all status updates of the execution
execution.latest_status is the latest status update of the execution

You can update the status of the execution at any place in the code by using the Progress object


Note that each progress update is an API call and can only be added if they are larger in 5 than their predecessors.

For example, if you perform 'progress.update(progress=4)' and then 'progress.update(progress=7)' you will not see the second update. However if you perform 'progress.update(progress=9)' after then you will be able to see it.

class ServiceRunner(dl.BaseServiceRunner):
    def detect(self, item: dl.Item, progress: dl.Progress): 
        progress.update(status='inProgress', progress=0, 
                        message='execution started')
        ###############
        ### DO WORK ###
        ###############
        progress.update(status='inProgress', progress=30)
        ####################
        ### DO MORE WORK ###
        ####################
        progress.update(status='inProgress', progress=80)
        ####################
        ### DO MORE WORK ###
        ####################
        progress.update(status='inProgress', progress=100, 
                        message='execution completed')

Retry Mechanism

Sometimes executions can fail due to service termination (or other errors that can cause the service to restart). In these cases, you can have the execution try and run automatically as many times as you desire. To do so you need to set the service max_attempts attribute. If you want to see how many attempts have been made for a single execution check its attempts' attribute.

Waiting for execution

Pause the process until the execution is complete (success/failed/aborted/etc.)
Execution run out of sync. You can wait for it to finish by:

execution.wait()

Execution cURL

Export the execution in a cURL format.

curl = service.executions.create(return_curl_only=True)

Rerun Execution

Easily rerun failed executions.

execution = dl.executions.get('execution_id')
execution.rerun()

Execution JSON

{
  "id": "string",
  "url": "string",
  "createdAt": "2020-11-18T17:41:25.740Z",
  "updatedAt": "2020-11-18T17:41:25.740Z",
  "creator": "string",
  "attempts": 0,
  "maxAttempts": 0,
  "toTerminate": true,
  "input": {},
  "output": {},
  "feedbackQueue": {
    "exchange": "string",
    "routing": "string"
  },
  "status": [
    {
      "timestamp": "2020-11-18T17:41:25.740Z",
      "status": "created",
      "message": "string",
      "percentComplete": 0,
      "error": {},
      "output": {}
    }
  ],
  "latestStatus": {
    "timestamp": "2020-11-18T17:41:25.740Z",
    "status": "created",
    "message": "string",
    "percentComplete": 0,
    "error": {},
    "output": {}
  },
  "duration": 0,
  "projectId": "string",
  "functionName": "string",
  "serviceId": "string",
  "triggerId": "string",
  "serviceName": "string",
  "packageId": "string",
  "packageName": "string",
  "packageRevision": 0,
  "serviceVersion": 0,
  "syncReplyTo": {
    "exchange": "string",
    "route": "string"
  }
}

What's Next