From aa64efe9e8957da6c122f9decaaa78dca83d14ee Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 22 Dec 2023 02:57:21 +0700 Subject: all: implement HTTP API to stop local or play execution The HTTP API for stopping execution have the following signature, DELETE /awwan/api/execute?id= If the ID is exist, the execution will be cancelled and return HTTP status 200 with the following body, Content-Type: application/json { "code": 200, } Otherwise it will return HTTP status 404 with error message. References: https://todo.sr.ht/~shulhan/awwan/9 --- testdata/http_server/execute/cancel.aww | 1 + testdata/http_server/execute/cancel_test.data | 55 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 testdata/http_server/execute/cancel.aww create mode 100644 testdata/http_server/execute/cancel_test.data (limited to 'testdata/http_server') diff --git a/testdata/http_server/execute/cancel.aww b/testdata/http_server/execute/cancel.aww new file mode 100644 index 0000000..46a443f --- /dev/null +++ b/testdata/http_server/execute/cancel.aww @@ -0,0 +1 @@ +sleep 300 diff --git a/testdata/http_server/execute/cancel_test.data b/testdata/http_server/execute/cancel_test.data new file mode 100644 index 0000000..4611da6 --- /dev/null +++ b/testdata/http_server/execute/cancel_test.data @@ -0,0 +1,55 @@ +Test cancelling Execute using HTTP API. +The SSE data is quoted to make the string viewable. + +>>> local:/cancel.aww:1- +{ + "mode": "local", + "script": "/cancel.aww", + "line_range": "1-" +} + +<<< local:/cancel.aww:1- +{ + "data": { + "mode": "local", + "script": "/cancel.aww", + "line_range": "1-", + "id": "local:/cancel.aww:1-:1701012060", + "begin_at": "2023-11-26T15:21:00Z", + "end_at": "", + "error": "", + "output": [] + }, + "code": 200 +} + +<<< local:/cancel.aww:1-:tail +event: open + +event: begin +data: "2023-11-26T15:21:00Z" + +event: message +data: "----/--/-- --:--:-- === BEGIN: local /cancel.aww 1-\n" +id: 0 + +event: message +data: "----/--/-- --:--:-- --> 1: sleep 300\n" +id: 1 + +event: message +data: "----/--/-- --:--:-- !!! ExecLocal: signal: killed\n" +id: 2 + +event: message +data: "Local: ExecLocal: signal: killed" +id: 2 + +event: end +data: "2023-11-26T15:21:00Z" +id: 2 + + + +<<< local:/cancel.aww:1-:response +{"message":"execution ID \"local:/cancel.aww:1-:1701012060\" has been cancelled","code":200} -- cgit v1.3