Adding StopTask endpoint and endpoint documentation

This commit is contained in:
Ian Roddis
2022-02-22 10:32:31 -04:00
parent 0ee198e3e7
commit b63739c0a9
5 changed files with 231 additions and 0 deletions

View File

@@ -50,6 +50,7 @@ namespace daggy::daggyd {
DAGGY_REST_HANDLER(handleGetDAGRunState); // X
DAGGY_REST_HANDLER(handleSetDAGRunState); // X
DAGGY_REST_HANDLER(handleGetTask); // X
DAGGY_REST_HANDLER(handleStopTask); // X
DAGGY_REST_HANDLER(handleGetTaskState); // X
DAGGY_REST_HANDLER(handleSetTaskState); // X

View File

@@ -167,6 +167,10 @@ namespace daggy::daggyd {
.bind(&Server::handleGetTask, this)
.produces(MIME(Application, Json))
.response(Http::Code::Ok, "Details of a specific task");
taskPath.route(desc_.del("/"))
.bind(&Server::handleStopTask, this)
.produces(MIME(Application, Json))
.response(Http::Code::Ok, "Kill a specific task");
/*
Task State paths
@@ -682,6 +686,25 @@ namespace daggy::daggyd {
}
}
void Server::handleStopTask(const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response)
{
if (!handleAuth(request))
return;
auto runID = request.param(":runID").as<DAGRunID>();
auto taskName = request.param(":taskName").as<std::string>();
{
std::lock_guard<std::mutex> lock(runnerGuard_);
auto it = runners_.find(runID);
if (runners_.find(runID) != runners_.end()) {
it->second->stopTask(taskName);
}
}
response.send(Pistache::Http::Code::Ok, "");
}
void Server::handleSetTaskState(const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response)
{

201
endpoints.rst Normal file
View File

@@ -0,0 +1,201 @@
Paths
===
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| Path | Verb | Description | Payload | Result |
+==============================================+========+===========================================================================+====================+===============================+
| ``/ready`` | GET | Ready check | | ``{ "msg": "Ya like DAGs?"}`` |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| ``/v1/dagruns?all=1`` | GET | Retrieve list of known dags | | :ref:`Example List of Runs` |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| ``/v1/dagrun`` | POST | Submit a DAG for execution | :ref:`Example DAG` | ``{ "runID": 0 }`` |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| ``/v1/dagrun/validate`` | POST | Submit a DAG for validation | :ref:`Example DAG` | ``{ "valid": true }`` |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| ``/v1/dagrun/{runid}`` | GET | Retrieve full state of dagrun | | :ref:`Example DAG Run` |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| ``/v1/dagrun/{runid}`` | DELETE | Kill a running DAG | | |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| ``/v1/dagrun/{runid}/state`` | GET | Retrieve current state of run | | ``{ "state": "QUEUED" }`` |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| ``/v1/dagrun/{runid}/state/{state}`` | PATCH | Set the state of a DAG Run. Can be used to restart an errored/killed DAG. | | ``{ "runID": 0 }`` |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| ``/v1/dagrun/{runid}/task/{taskName}`` | GET | Get all the details of a specific task. | | :ref:`Example Task Details` |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| ``/v1/dagrun/{runid}/task/{taskName}`` | DELETE | Kill a task | | |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
| ``/v1/dagrun/{runid}/task/{taskName}/state`` | GET | Get the current state of a task | | ``{ "state": "QUEUED" }`` |
+----------------------------------------------+--------+---------------------------------------------------------------------------+--------------------+-------------------------------+
Example List of Runs
===
.. code:: json
[
{
"runID": 0,
"tag": "mediumtest",
"state": "COMPLETED",
"startTime": "1645112245996647771",
"lastUpdate": "1645112265427198113",
"taskCounts": {
"COMPLETED": 25
}
},
{
"runID": 1,
"tag": "mediumtest",
"state": "COMPLETED",
"startTime": "1645218441353189612",
"lastUpdate": "1645218455775103710",
"taskCounts": {
"COMPLETED": 25
}
},
{
"runID": 2,
"tag": "mediumtest",
"state": "RUNNING",
"startTime": "1645539903281234588",
"lastUpdate": "1645539912499992547",
"taskCounts": {
"COMPLETED": 11,
"RUNNING": 14
}
}
]
Example DAG
===
.. code:: json
{
"tag": "mediumtest",
"parameters": {
"JOBNO": [
"1", "2"
]
},
"tasks": {
"simple": {
"job": {
"command": [ "/usr/bin/python3", "script.py", "{{JOBNO}}" ],
"cores": "1",
"memoryMB": "100"
}
}
}
}
Example DAG Run
===
.. code:: json
{
"runID": 0,
"tag": "mediumtest",
"tasks": {
"simple_0": {
"maxRetries": 0,
"retryIntervalSeconds": 0,
"job": {
"environment": [],
"memoryMB": "100",
"cores": "1",
"command": [
"/usr/bin/python3",
"script.py",
"1"
]
},
"children": [],
"parents": [],
"isGenerator": false
},
"simple_1": {
"maxRetries": 0,
"retryIntervalSeconds": 0,
"job": {
"environment": [],
"memoryMB": "100",
"cores": "1",
"command": [
"/usr/bin/python3",
"script.py",
"2"
]
},
"children": [],
"parents": [],
"isGenerator": false
}
},
"taskStates": {
"simple_0": "COMPLETED",
"simple_1": "COMPLETED"
},
"taskAttempts": {
"simple_0": [
{
"startTime": "1645112246001010638",
"stopTime": "1645112256116473300",
"rc": 0,
"outputLog": "Echoing script.py 1 env is not found, value is >><< \n",
"errorLog": "",
"executorLog": ""
}
],
"simple_1": [
{
"startTime": "1645112246001027500",
"stopTime": "1645112256115818901",
"rc": 0,
"outputLog": "Echoing script.py 2 env is not found, value is >><< \n",
"errorLog": "",
"executorLog": ""
}
]
},
"dagStateChanges": [
{
"time": "1645112245996647771",
"state": "QUEUED"
},
{
"time": "1645112245997607895",
"state": "RUNNING"
},
{
"time": "1645112265427198113",
"state": "COMPLETED"
}
]
}
Example Task Details
===
.. code:: json
{
"maxRetries": 0,
"retryIntervalSeconds": 0,
"job": {
"environment": [],
"memoryMB": "100",
"cores": "1",
"command": [
"/usr/bin/python3",
"script.py",
"1"
]
},
"children": [],
"parents": [],
"isGenerator": false
}

View File

@@ -31,6 +31,7 @@ namespace daggy {
TaskDAG run();
void resetRunning();
void stop(bool kill = false, bool blocking = false);
void stopTask(const std::string &taskName);
private:
void collectFinished();

View File

@@ -90,6 +90,11 @@ namespace daggy {
}
}
void DAGRunner::stopTask(const std::string &taskName)
{
executor_.stop(runID_, taskName);
}
void DAGRunner::queuePending()
{
if (!running_)