Make the initial state user-definable
This commit is contained in:
parent
7436b65210
commit
518648b238
2 changed files with 9 additions and 5 deletions
|
@ -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 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.
|
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
|
## HTTP API
|
||||||
|
|
||||||
|
@ -39,10 +39,11 @@ $ curl -X POST $JOBQ/api/v0/job --data '{"query": [["IS", "json_extract(state, '
|
||||||
```
|
```
|
||||||
|
|
||||||
### POST /api/v0/job/create
|
### 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
|
"id": 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,10 +221,13 @@ def get_jobs():
|
||||||
def create_job():
|
def create_job():
|
||||||
"""Create a 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(
|
id, state = current_app.queries.job_create(
|
||||||
request.db,
|
request.db,
|
||||||
payload=json.dumps(request.get_json(force=True)),
|
payload=json.dumps(job),
|
||||||
state=None,
|
state=json.dumps(state),
|
||||||
)
|
)
|
||||||
return jsonify({"id": id, "state": state}), 200
|
return jsonify({"id": id, "state": state}), 200
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue