From 692327e2762b28efb21de803ad6726b0a0c1ccf8 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sat, 14 Aug 2021 11:23:27 -0600 Subject: [PATCH] Be consistent about 'payload' --- projects/jobq/README.md | 4 ++-- projects/jobq/src/python/jobq/__main__.py | 4 ++-- projects/jobq/src/python/jobq/rest/api.py | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/projects/jobq/README.md b/projects/jobq/README.md index 337a55d..fa0891d 100644 --- a/projects/jobq/README.md +++ b/projects/jobq/README.md @@ -39,11 +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 in the given state. +Given a JSON document as the POST body, create a new job with a payload in the given state. If state is not provided, the state `null` is used. ``` -$ curl -X POST $JOBQ/api/v0/job/create --data '{"state": ["CREATED"], "job": {"msg": "Hello, world!"}}' | jq . +$ curl -X POST $JOBQ/api/v0/job/create --data '{"state": ["CREATED"], "payload": {"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 a9900d0..818fef1 100644 --- a/projects/jobq/src/python/jobq/__main__.py +++ b/projects/jobq/src/python/jobq/__main__.py @@ -222,11 +222,11 @@ def create_job(): """Create a job.""" blob = request.get_json(force=True) - job = blob["job"] + payload = blob["payload"] state = blob.get("state", None) id, state = current_app.queries.job_create( request.db, - payload=json.dumps(job), + payload=json.dumps(payload), state=json.dumps(state), ) return jsonify({"id": id, "state": state}), 200 diff --git a/projects/jobq/src/python/jobq/rest/api.py b/projects/jobq/src/python/jobq/rest/api.py index b6dc7e5..45fb038 100644 --- a/projects/jobq/src/python/jobq/rest/api.py +++ b/projects/jobq/src/python/jobq/rest/api.py @@ -53,11 +53,12 @@ class JobqClient(object): json={"query": query, "state": state}).json()) - def create(self, payload: object) -> DehydratedJob: + def create(self, payload: object, state=None) -> DehydratedJob: """Create a new job in the system.""" job_frag = self._session.post(self._url + "/api/v0/job/create", - json=payload)\ + json={"payload": payload, + "state": state})\ .json() return self._job(job_frag)