Extra Horizon
GitHub
  • Extra Horizon Documentation
  • Getting Started
    • Start familiarizing yourself
  • Tutorials
    • Medical Device Tutorial
      • Preparation
      • Build your first prototype
        • Define a data model
        • Configure your workflows
          • Workflow 1: Analyze a measurement
          • Workflow 2: Create & store a PDF report
          • Workflow 3: Send an e-mail
        • Define your permissions
          • Update your schema with user permissions
          • Update your schema with group permissions
        • Build the Front-End
          • Set up oAuth in your backend
          • Demo login page
      • Summary & Wrap up
    • Polysomnography (PSG) Tutorial
    • Retool - Building dashboards Tutorial
  • FAQ
    • General
  • Services
    • Identity and Access Management
      • User service
        • Users
        • Groups
        • Global roles
        • Configuration
      • Auth Service
        • Applications
        • OAuth2
        • OAuth1
        • MFA
        • OpenID Connect
          • Google Cloud
          • Azure ADFS
    • Data Management
      • File Service
      • Data Service
        • Schemas
        • Documents
        • FAQ Data Service
    • Automation
      • Task Service
        • Functions
        • Tasks
        • API Functions
        • Examples
          • Hello world (JS)
          • Hello world (Py)
          • Hello world (Docker)
        • FAQ
      • Dispatchers Service
      • Event Service
        • System Events
    • Communication
      • Notification Service
        • Notifications
        • Settings
      • Mail Service
    • Other
      • Localization Service
        • Language Codes
      • Template Service
        • Localizations
      • Payments Service
        • Subscriptions
        • Stripe
        • iOS App Store
      • Configurations Service
  • API Reference
    • OpenAPI Specifications
    • 📦Changelog
      • Per-service Changelog
    • Postman Reference Collection
  • Tools
    • SDK
    • CLI
    • Control Center
  • Additional Resources
    • Resource Query Language (RQL)
    • Handling Errors
    • GitHub
    • API interaction (Python)
    • Migration guide: Enabling verification request limiting
  • ExH Platform
    • 🙋Support
    • ⏱️Usage and Performance
    • 🔓Security
    • 🗺️Regions
    • ⚖️Cloud Subscription Agreement
    • 🇺🇸CFR 21 Part 11
Powered by GitBook
On this page
  • Creating a task
  • Scheduling
  • Listing scheduled tasks
  • Task Lifecycle
  • Queuing
  • Execution status
  • The Task Failed Event

Was this helpful?

  1. Services
  2. Automation
  3. Task Service

Tasks

PreviousFunctionsNextAPI Functions

Last updated 8 months ago

Was this helpful?

Creating a task

Tasks represent a scheduled or planned function. Tasks can give you insights in to when the function will be executed and provide insights into the success or failure of the execution.

Scheduling

By data service transitions

When configuring your application's data model, it's possible to attach an to a transition. Triggering the scheduling of a task is one of the available actions. Read more about how to implement this functionality in the .

Scheduling via the SDK

In JavaScript/TypeScript environments, our can be used to schedule a task:

await exh.tasks.create({
    functionName: 'yourFunctionName',
    data: {...yourData},
    priority: 1,
    startTimestamp: new Date(Date.now()),
    tags: ['mytag']
});

Scheduling via an API call

See the to learn how to schedule a Task via the API

Listing scheduled tasks

await exh.tasks.find();

A Task object is uniquely identified within the Task Service by its id. It contains a number of attributes

{
  "id": "757f191a810c19729de860ae",
  "functionName": "testFunction",
  "status": "new",
  "statusChangedTimestamp": "2021-09-29T15:17:07.051Z",
  "data": {
    "my_key": "My Value"
  },
  "tags": [
    "my_tag"
  ],
  "startTimestamp": "2021-09-29T15:17:07.051Z",
  "priority": 1,
  "createdByApplicationId": "6672ede774a7bd291fb0bea4",
  "createdByUserId": "58ff75ad4cedfd0005f80951",
  "creationTimestamp": "2021-09-29T15:17:07.051Z",
  "updateTimestamp": "2021-09-29T15:17:07.051Z"
}
  • functionName - the name of the AWS Lambda function that should be executed. This function must be created in the same AWS account as the Extra Horizon deployment.

  • status - Task status, see below for more information

  • statusChangedTimestamp - timestamp when the status was last updated

  • data - [optional] A key-value object where input to the function is provided

  • tags - [optional] Descriptive keywords that improve the search experience. For example, they can be used to trace automated Tasks by adding the Task id’s to the tags list.

  • startTimestamp - set when the task should start

  • priority - define which tasks should get precedence in a queue

  • createdByApplicationId - The application which created the task

  • createdByUserId - The user who created the task

If you define a function schedule, you will only see the next scheduled task execution at the moment when it starts.

Task Lifecycle

Queuing

When multiple tasks need to be executed in a short period, they may be placed in a queue. Tasks are initially ordered by their startTimestamp attribute, meaning the earliest scheduled task will be executed first.

However, if tasks are queued, the priority attribute can be used to control the execution order. The priority attribute overrides the startTimestamp, so tasks with a higher priority value will be executed before those with a lower priority.

To ensure critical tasks are executed first when queuing occurs, assign them a higher priority value.

The priority attribute can range from -9007199254740991 to 9007199254740991. When not specified, the default value 0 is used.

Execution status

The status and statusChangedTimestamp attributes are updated according to the Task’s execution progress. A newly created Task (status: new) can be revoked via the Cancel a Task endpoint (status: canceled).

Once the Task Service invokes the specified AWS Lambda function, the Task receives the inProgress status and the execution of the code cannot be halted via Extra Horizon.

Upon successful execution of the code, AWS Lambda reports back to the Task Service and the Task status is updated to complete.

Retries

Available since v1.3.0

If an error occurs while executing a Task, the Task Service will check if the function has defined a retry policy of the function.

When a retry policy is applicable the Task status is set to retried and a new Task is created with the same properties. The new Task will include a retryForTaskIds field containing the id of the original Task. In turn, the original task will receive a retriedByTaskId field holding the id of the new Task.

Task failures

If an error occurs while no restart policy is defined or the maximum number of tries have been reached the Task status is set to failed.

If the system cannot determine the outcome of the Task execution, the Task status is also set to failed. In such cases, an error named zombieTaskCleaned will be included in the Task.

The Task Failed Event

Available since v1.4.0

When a Task reaches the failed status, a task_failed event is published.

The event can be used to react to Task failures. This could for instance be used for monitoring, alerting or implementing custom retry logic.

A task_failed event contains the following attributes:

{
    "type": "task_failed",
    "content": {
        "id": "757f191a810c19729de860ae",
        "functionName": "testFunction",
        "error": {
            "type": "runtime",
            "name": "TypeError",
            "message": "Cannot read property 'x' of undefined"
        }
    }
}
  • content.id - the id of the failed Task.

  • content.functionName - the name of the function the failed Task was trying to execute.

  • content.error - the error that led to the failure of the Task.

See the to learn more about retry policies.

Extra Horizon SDK
Tasks Service API Reference
action
Data Service documentation
Functions section