From 14a1452f22530133e3bd9eb2bee6ae606d813b53 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sat, 14 Aug 2021 11:18:19 -0600 Subject: [PATCH] Make the initial state user-definable --- projects/jobq/README.md | 7 ++++--- projects/jobq/src/python/jobq/__main__.py | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/projects/jobq/README.md b/projects/jobq/README.md index 1e39e6f..337a55d 100644 --- a/projects/jobq/README.md +++ b/projects/jobq/README.md @@ -5,7 +5,7 @@ Each _job_ (a JSON request blob POSTed by the user) has an attached log of _even Users may change the _state_ of a job, and doing so automatically produces a new _event_ recording the change. Users may manually add _events_ to the log. -Note that, while we strongly suggest that _state_ should always be a tagged tuple and the default is `["CREATED"]`, no constraints are placed on its contents. +Note that, while we strongly suggest that _state_ should always be a tagged tuple, no constraints are placed on its contents. ## HTTP API @@ -39,10 +39,11 @@ $ curl -X POST $JOBQ/api/v0/job --data '{"query": [["IS", "json_extract(state, ' ``` ### POST /api/v0/job/create -Given a JSON document as the POST body, create a new job. +Given a JSON document as the POST body, create a new job in the given state. +If state is not provided, the state `null` is used. ``` -$ curl -X POST $JOBQ/api/v0/job/create --data '{"msg": "Hello, world!"}' | jq . +$ curl -X POST $JOBQ/api/v0/job/create --data '{"state": ["CREATED"], "job": {"msg": "Hello, world!"}}' | jq . { "id": 1 } diff --git a/projects/jobq/src/python/jobq/__main__.py b/projects/jobq/src/python/jobq/__main__.py index 1cfe090..a9900d0 100644 --- a/projects/jobq/src/python/jobq/__main__.py +++ b/projects/jobq/src/python/jobq/__main__.py @@ -221,10 +221,13 @@ def get_jobs(): def create_job(): """Create a job.""" + blob = request.get_json(force=True) + job = blob["job"] + state = blob.get("state", None) id, state = current_app.queries.job_create( request.db, - payload=json.dumps(request.get_json(force=True)), - state=None, + payload=json.dumps(job), + state=json.dumps(state), ) return jsonify({"id": id, "state": state}), 200