Make the initial state user-definable

This commit is contained in:
Reid 'arrdem' McKenzie 2021-08-14 11:18:19 -06:00
parent ccac0bb3fe
commit 14a1452f22
2 changed files with 9 additions and 5 deletions

View file

@ -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
}

View file

@ -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