refine timestamps in json signals api

*   API change: in update signals, allow setting a start time relative
    to now. This is an accuracy improvement in the case where the client
    has been retrying an initial request for a while. Kind of an obscure
    corner case but easy enough to address. And use a more convenient
    enum representation.

*   in update signals, choose `now` before acquiring the database lock.
    If lock acquisition takes a long time, this more accurately reflects
    the time the caller intended.

*   in general, make Time and Duration (de)serializable and use them
    in json types. This makes the types more self-describing, with
    better debug printing on both the server side and on the client
    library (in moonfire-playground). To make this work, base has to
    import serde which initially seemed like poor layering to me, but
    serde seems to be imported in some pretty foundational Rust crates
    for this reason. I'll go with it.
This commit is contained in:
Scott Lamb
2021-04-21 10:44:01 -07:00
parent 5da5494dfb
commit 1e314e09d0
6 changed files with 61 additions and 53 deletions

View File

@@ -658,13 +658,12 @@ make. It should be a dict with these attributes:
* `signalIds`: a list of signal ids to change. Must be sorted.
* `states`: a list (one per `signalIds` entry) of states to set.
* `startTime90k`: (optional) The start of the observation in 90 kHz units
since 1970-01-01 00:00:00 UTC; commonly taken from an earlier response. If
absent, assumed to be now.
* `endBase`: if `epoch`, `relEndTime90k` is relative to 1970-01-01 00:00:00
UTC. If `now`, epoch is relative to the current time.
* `relEndTime90k` (optional): The end of the observation, relative to the
specified base. Note this time is allowed to be in the future.
* `start`: the starting time of the change, as a dict of the form
`{'base': 'epoch', 'rel90k': t}` or `{'base': 'now', 'rel90k': t}`. In
the `epoch` form, `rel90k` is 90 kHz units since 1970-01-01 00:00:00 UTC.
In the `now` form, `rel90k` is relative to current time and may be
negative.
* `end`: the ending time of the change, in the same form as `start`.
The response will be an `application/json` body dict with the following
attributes:
@@ -687,8 +686,8 @@ Request:
{
"signalIds": [1],
"states": [2],
"endBase": "now",
"relEndTime90k": 5400000
"start": {"base": "now", "rel90k": 0},
"end": {"base": "now", "rel90k": 5400000}
}
```
@@ -711,8 +710,8 @@ Request:
{
"signalIds": [1],
"states": [2],
"endBase": "now",
"relEndTime90k": 5400000
"start": {"base": "epoch", "rel90k": 140067468000000},
"end": {"base": "now", "rel90k": 5400000}
}
```
@@ -735,8 +734,8 @@ Request:
{
"signalIds": [1],
"states": [2],
"endBase": "now",
"relEndTime90k": 5400000
"start": {"base": "now", "rel90k": 0},
"end": {"base": "now", "rel90k": 5400000}
}
}
```