# Schedule

This endpoint is used to create, update, search or delete schedules for a particular workspace inside an organization, this is useful when you need to create schedule task or running jobs in a particular time.

### Entity fields:

| Path                              | Type   | Description                                                                                                                                                                                                   |
| --------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| data.type                         | string | Should be "template"                                                                                                                                                                                          |
| data.attributes.cron              | string | Cron expression to schedule a job inside a workspace. For more information please visit [Quartz documentation](http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/tutorial-lesson-06.html). |
| data.attributes.tcl               | string | Terrakube configuration language in base64                                                                                                                                                                    |
| data.attributes.templateReference | string | Terrakube template id                                                                                                                                                                                         |

{% hint style="info" %}
To better understand Terrakube Configuration Language job templates please refer to the following [GitHub repository.](https://github.com/AzBuilder/terrakube-extensions)
{% endhint %}

### Example:

```
{
  "data": {
    "type": "schedule",
    "attributes": {
      "cron": "0 0/1 * * * ?",
      "tcl": "{{templateSample}}"
    }
  }
}
```

### Supported Operations

## GET /workspace/{workspaceId}/schedule

> Returns the relationship schedule

```json
{"openapi":"3.0.1","info":{"title":"Elide Service","version":"0.0.1"},"tags":[{"name":"schedule"}],"servers":[{"url":"/api/v1"}],"paths":{"/workspace/{workspaceId}/schedule":{"get":{"tags":["schedule"],"description":"Returns the relationship schedule","parameters":[{"name":"sort","in":"query","description":"Sorts the collection on the selected attributes.  A prefix of '-' sorts descending","style":"form","explode":false,"schema":{"type":"array","items":{"type":"string","enum":["createdBy","-createdBy","cron","-cron","description","-description","enabled","-enabled","tcl","-tcl","templateReference","-templateReference","updatedBy","-updatedBy","id","-id"]}}},{"name":"fields[schedule]","in":"query","description":"Selects the set of schedule fields that should be returned in the result.","style":"form","explode":false,"schema":{"type":"array","items":{"type":"string","enum":["createdBy","createdDate","cron","description","enabled","tcl","templateReference","updatedBy","updatedDate","workspace"]}}},{"name":"include","in":"query","description":"Selects the set of relationships that should be expanded as a compound document in the result.","style":"form","explode":false,"schema":{"type":"array","items":{"type":"string","enum":["workspace"]}}},{"name":"filter[schedule]","in":"query","description":"Filters the collection of schedule using a 'disjoint' RSQL expression","schema":{"type":"string"}},{"name":"page[number]","in":"query","description":"Number of pages to return.  Can be used with page[size]","schema":{"type":"integer","format":"int32"}},{"name":"page[size]","in":"query","description":"Number of elements per page.  Can be used with page[number]","schema":{"type":"integer","format":"int32"}},{"name":"page[offset]","in":"query","description":"Offset from 0 to start paginating.  Can be used with page[limit]","schema":{"type":"integer","format":"int32"}},{"name":"page[limit]","in":"query","description":"Maximum number of items to return.  Can be used with page[offset]","schema":{"type":"integer","format":"int32"}},{"name":"page[totals]","in":"query","description":"For requesting total pages/records be included in the response page meta data","schema":{"type":"string"}}],"responses":{"200":{"description":"Successful response","content":{"application/vnd.api+json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/schedule"}},"included":{"uniqueItems":true,"type":"array","description":"Included resources","items":{"type":"object","properties":{"type":{"type":"string"},"id":{"type":"string"},"attributes":{"type":"object"},"relationships":{"type":"object"}}}}}}}}}}}}},"components":{"schemas":{"schedule":{"type":"object","properties":{"type":{"type":"string","description":""},"id":{"type":"string"},"attributes":{"type":"object","properties":{"createdBy":{"type":"string","readOnly":false,"writeOnly":false},"createdDate":{"type":"string","readOnly":false,"writeOnly":false},"cron":{"type":"string","readOnly":false,"writeOnly":false},"description":{"type":"string","readOnly":false,"writeOnly":false},"enabled":{"type":"boolean","readOnly":false,"writeOnly":false},"tcl":{"type":"string","readOnly":false,"writeOnly":false},"templateReference":{"type":"string","readOnly":false,"writeOnly":false},"updatedBy":{"type":"string","readOnly":false,"writeOnly":false},"updatedDate":{"type":"string","readOnly":false,"writeOnly":false}}},"relationships":{"type":"object","properties":{"workspace":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["workspace"]},"id":{"type":"string"}},"readOnly":false,"writeOnly":false}}}}}}}}}}}
```

## POST /workspace/{workspaceId}/schedule

> Creates an item of type schedule and adds it to schedule

```json
{"openapi":"3.0.1","info":{"title":"Elide Service","version":"0.0.1"},"tags":[{"name":"schedule"}],"servers":[{"url":"/api/v1"}],"paths":{"/workspace/{workspaceId}/schedule":{"post":{"tags":["schedule"],"description":"Creates an item of type schedule and adds it to schedule","requestBody":{"content":{"application/vnd.api+json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/schedule"},"included":{"uniqueItems":true,"type":"array","description":"Included resources","items":{"type":"object","properties":{"type":{"type":"string"},"id":{"type":"string"},"attributes":{"type":"object"},"relationships":{"type":"object"}}}}}}}}},"responses":{"201":{"description":"Successful response","content":{"application/vnd.api+json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/schedule"},"included":{"uniqueItems":true,"type":"array","description":"Included resources","items":{"type":"object","properties":{"type":{"type":"string"},"id":{"type":"string"},"attributes":{"type":"object"},"relationships":{"type":"object"}}}}}}}}}}}}},"components":{"schemas":{"schedule":{"type":"object","properties":{"type":{"type":"string","description":""},"id":{"type":"string"},"attributes":{"type":"object","properties":{"createdBy":{"type":"string","readOnly":false,"writeOnly":false},"createdDate":{"type":"string","readOnly":false,"writeOnly":false},"cron":{"type":"string","readOnly":false,"writeOnly":false},"description":{"type":"string","readOnly":false,"writeOnly":false},"enabled":{"type":"boolean","readOnly":false,"writeOnly":false},"tcl":{"type":"string","readOnly":false,"writeOnly":false},"templateReference":{"type":"string","readOnly":false,"writeOnly":false},"updatedBy":{"type":"string","readOnly":false,"writeOnly":false},"updatedDate":{"type":"string","readOnly":false,"writeOnly":false}}},"relationships":{"type":"object","properties":{"workspace":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["workspace"]},"id":{"type":"string"}},"readOnly":false,"writeOnly":false}}}}}}}}}}}
```

## DELETE /workspace/{workspaceId}/schedule/{scheduleId}

> Deletes an instance of type schedule

```json
{"openapi":"3.0.1","info":{"title":"Elide Service","version":"0.0.1"},"tags":[{"name":"schedule"}],"servers":[{"url":"/api/v1"}],"paths":{"/workspace/{workspaceId}/schedule/{scheduleId}":{"delete":{"tags":["schedule"],"description":"Deletes an instance of type schedule","responses":{"204":{"description":"Successful response"}}}}}}
```

## PATCH /workspace/{workspaceId}/schedule/{scheduleId}

> Modifies an instance of type schedule

```json
{"openapi":"3.0.1","info":{"title":"Elide Service","version":"0.0.1"},"tags":[{"name":"schedule"}],"servers":[{"url":"/api/v1"}],"paths":{"/workspace/{workspaceId}/schedule/{scheduleId}":{"patch":{"tags":["schedule"],"description":"Modifies an instance of type schedule","requestBody":{"content":{"application/vnd.api+json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/schedule"},"included":{"uniqueItems":true,"type":"array","description":"Included resources","items":{"type":"object","properties":{"type":{"type":"string"},"id":{"type":"string"},"attributes":{"type":"object"},"relationships":{"type":"object"}}}}}}}}},"responses":{"204":{"description":"Successful response"}}}}},"components":{"schemas":{"schedule":{"type":"object","properties":{"type":{"type":"string","description":""},"id":{"type":"string"},"attributes":{"type":"object","properties":{"createdBy":{"type":"string","readOnly":false,"writeOnly":false},"createdDate":{"type":"string","readOnly":false,"writeOnly":false},"cron":{"type":"string","readOnly":false,"writeOnly":false},"description":{"type":"string","readOnly":false,"writeOnly":false},"enabled":{"type":"boolean","readOnly":false,"writeOnly":false},"tcl":{"type":"string","readOnly":false,"writeOnly":false},"templateReference":{"type":"string","readOnly":false,"writeOnly":false},"updatedBy":{"type":"string","readOnly":false,"writeOnly":false},"updatedDate":{"type":"string","readOnly":false,"writeOnly":false}}},"relationships":{"type":"object","properties":{"workspace":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["workspace"]},"id":{"type":"string"}},"readOnly":false,"writeOnly":false}}}}}}}}}}}
```

## GET /workspace/{workspaceId}/schedule/{scheduleId}

> Returns an instance of type schedule

```json
{"openapi":"3.0.1","info":{"title":"Elide Service","version":"0.0.1"},"tags":[{"name":"schedule"}],"servers":[{"url":"/api/v1"}],"paths":{"/workspace/{workspaceId}/schedule/{scheduleId}":{"get":{"tags":["schedule"],"description":"Returns an instance of type schedule","parameters":[{"name":"fields[schedule]","in":"query","description":"Selects the set of schedule fields that should be returned in the result.","style":"form","explode":false,"schema":{"type":"array","items":{"type":"string","enum":["createdBy","createdDate","cron","description","enabled","tcl","templateReference","updatedBy","updatedDate","workspace"]}}},{"name":"include","in":"query","description":"Selects the set of relationships that should be expanded as a compound document in the result.","style":"form","explode":false,"schema":{"type":"array","items":{"type":"string","enum":["workspace"]}}}],"responses":{"200":{"description":"Successful response","content":{"application/vnd.api+json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/schedule"},"included":{"uniqueItems":true,"type":"array","description":"Included resources","items":{"type":"object","properties":{"type":{"type":"string"},"id":{"type":"string"},"attributes":{"type":"object"},"relationships":{"type":"object"}}}}}}}}}}}}},"components":{"schemas":{"schedule":{"type":"object","properties":{"type":{"type":"string","description":""},"id":{"type":"string"},"attributes":{"type":"object","properties":{"createdBy":{"type":"string","readOnly":false,"writeOnly":false},"createdDate":{"type":"string","readOnly":false,"writeOnly":false},"cron":{"type":"string","readOnly":false,"writeOnly":false},"description":{"type":"string","readOnly":false,"writeOnly":false},"enabled":{"type":"boolean","readOnly":false,"writeOnly":false},"tcl":{"type":"string","readOnly":false,"writeOnly":false},"templateReference":{"type":"string","readOnly":false,"writeOnly":false},"updatedBy":{"type":"string","readOnly":false,"writeOnly":false},"updatedDate":{"type":"string","readOnly":false,"writeOnly":false}}},"relationships":{"type":"object","properties":{"workspace":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["workspace"]},"id":{"type":"string"}},"readOnly":false,"writeOnly":false}}}}}}}}}}}
```

{% hint style="info" %}
For a complete list of organization operation please visit the [OpenAPI specification](https://github.com/AzBuilder/terrakube-server/tree/main/openapi-spec)
{% endhint %}
