Skip to content

Saved Jobs

Usman Shahid edited this page Feb 12, 2019 · 2 revisions

In addition to launching commands as jobs, a job specification can be saved for future execution.

Creating a Saved Job (PUT /v1/saved)

To create a saved job, simply PUT the job specification on the /v1/saved path:

PUT http://localhost:2112/v1/saved
{
	"Id": "my-saved",
	"Executions": [
		{
			"Executable": {
				"Command": "echo",
				"Args": ["shhttp is awesome"], 
				"Env": {
					"VAR1": "Val1"
				}
			}
		},
		{
			"Executable": {
				"Command": "echo",
				"Args": ["\"winner\nwinner\nchicken\ndinner\"", "|", "grep", "chicken"],
				"Shell": true,
				"Env": {
					"VAR2": "Val2"
				}
			}
		}
	]
}

Notice how we've set the Id of the job. This is the Id used to later reference the job. If the Id is not set, it is autogenerated. The response to this request contains the Id:

HTTP 201
{
    "id": "my-saved"
}

Running a Saved Job (POST /v1/saved/{id})

A saved job can be run by POSTing on the /v1/saved/{saved-job-id} endpoint e.g. for the above job, do the following:

POST http://localhost:2112/v1/saved/my-saved

The response will return a new Id. This is the Id of the running job which you can use to get the job status using the Jobs API:

{
    "id": "1549968731616066000-ec2d7fd6-6ce8-469c-86b2-8856c6f179f2"
}

Getting Saved Jobs Ids (GET /v1/saved)

GET http://localhost:2112/v1/saved

Will return:

{
    "Ids": [
        "my-saved"
    ]
}

Getting Saved Job (GET /v1/saved/{id})

GET http;//localhost:2112/v1/saved/my-saved

Will return:

{
    "Id": "my-saved",
    "Executions": [
        {
            "Executable": {
                "Command": "echoecho",
                "Args": [
                    "shhttp is awesome"
                ],
                "BaseDir": "",
                "Stdin": "",
                "Shell": false,
                "Env": {
                    "VAR1": "Val1"
                }
            },
            "Stdout": "",
            "Stderr": "",
            "ExitCode": 0,
            "Start": 0,
            "End": 0
        },
        {
            "Executable": {
                "Command": "echo",
                "Args": [
                    "\"winner\nwinner\nchicken\ndinner\"",
                    "|",
                    "grep",
                    "chicken"
                ],
                "BaseDir": "",
                "Stdin": "",
                "Shell": true,
                "Env": {
                    "VAR2": "Val2"
                }
            },
            "Stdout": "",
            "Stderr": "",
            "ExitCode": 0,
            "Start": 0,
            "End": 0
        }
    ],
    "Status": "",
    "Created": 0,
    "LastModified": 0,
    "IgnoreErrors": false
}

Delete a Saved Job (DELETE /v1/saved/{id})

DELETE http://localhost:2112/v1/saved/my-saved
Clone this wiki locally