fbpx

Scheduling Jobs

Creating and running a Job in nomad without sufficient capacity will fail the Job. Being able to send Job requests directly to Spotisnt will prevent Jobs failing due to lack of capacity issue. This means we will scale up if needed before running the Job, and then create and run it.

How does this work?

Spotinst provides two API call for Job management. One to create the schedule and another to monitor it.
Please review Spotinst API semantics right here: Spotinst API Semantics Documentation

Create Job execution 

Submit a POST request to the following URL:

https://api.spotinst.io/aws/ec2/nomad/jobExecution

Provide the following arguments:

nomadJobExecution – (Required Object) – Holds the parameters for the Job execution

nomadJobExecution.groupId – (Required String) – Provide the Elastigroup ID that should execute the Jobs.

nomadJobExecution.jobSpecification – (Required Object) – Provide details about the required Job and its properties.
For more information please see: Nomad job-specification

Example Request:

{
    "nomadJobExecution": {
    "groupId": "sig-12345",
    "jobSpecification": {
      "Job": {
        "ID": "docs1234556",
        "Name": "docs",
        "Type": "service",
        "Priority": 50,
        "Datacenters": [
          "dc1"
        ],
        "TaskGroups": [
          {
            "Name": "example",
            "Count": null,
            "Constraints": null,
            "Tasks": [...]
          }
        ],
        "Update": {}
      }
    }
  }
}

Example Response:

{
  "items": [
    {
      "groupId": "sig-123",
      "executionId": "nmr-12345",
      "jobSpecification": {
        "job": "..."
      },
      "state": "STARTED"
    }
  ]
}
Get Job execution status

Submit a GET request to the following URL:

https://api.spotinst.io/aws/ec2/nomad/jobExecution/{executionId}

Provide the following path parameters:

executionId – The Job execution ID as provided in the create response, for example: nmr-12345

Return value:

state – The Job execution state. Possible values: STARTED | SCALING TO MEET DEMANDS | ALLOCATED | FAILED

Example Response: 

{
  "items": [
    {
      "groupId": "sig-123",
      "executionId": "nmr-12345",
      "jobSpecification": {
        "job": "..."
      },
      "state": "STARTED"
    }
  ]
}