Repository navigation
Conversation
9f3141d to
b607783
Compare
llucax
left a comment
There was a problem hiding this comment.
It might be useful to comment in more detail why there was any imprecision in "Fix start_time conversion imprecision bug" and how it is fixed by the common functions, at least for me it is not clear so I might make the same mistake in other API clients.
2a5cb78 to
3a12a94
Compare
|
Updated:
|
96ff3ea to
36a64cd
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
I suggest opening a new PR with the new commits, as they are not really necessary to be in this PR and we were close to finish the review. I have a few comments for the new commits and that will make merging this PR more time consuming. |
Awesome, thanks! Now I remember. |
llucax
left a comment
There was a problem hiding this comment.
With this small change, this should be ready to merge up to the commit changing the Client.create() method.
| """ | ||
| async for dispatch in self.list(microgrid_id=request.microgrid_id): | ||
| found = True | ||
| for key, value in request.__dict__.items(): |
There was a problem hiding this comment.
Are you sure this works as expected? When I look at __dict__ in a message it also have __slots__ and other stuff, maybe it would be better to use the google.protobuf.json_format.MessageToDict function?
You'll need to set at lest including_default_value_fields=True and I guess it would be better to set use_integers_for_enums=True and maybe something like float_precision=8.
There was a problem hiding this comment.
It at least seems to be what I expected it to be..
These are the fields and their values I get in my loop
request.microgrid_id = 1
request.type = ECHO_FREQUENCY
request.start_time = 2024-04-18 18:44:42.901963+00:00
request.duration = 0:05:00
request.selector = ComponentCategory.INVERTER
request.active = True
request.dry_run = False
request.payload = {'font': 'Times New Roman'}
request.recurrence = RecurrenceRule(frequency=<Frequency.UNSPECIFIED: 0>, interval=0, end_criteria=None, byminutes=[], byhours=[], byweekdays=[], bymonthdays=[], bymonths=[])
There was a problem hiding this comment.
Ah, besides, this isn't a Protobuf object, this is our abstraction. We only convert to protobuf right before sending the request.
|
Responded to comment and removed the unrelated commits |
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Use client-common v0.1.0 and api-dispatch v0.13.0
To properly convert from protobuf to datetime, one has to explicitly
handle the nanoseconds like so:
```python
# Add microseconds and add nanoseconds converted to microseconds
microseconds = int(ts.nanos / 1000)
return datetime.fromtimestamp(ts.seconds + microseconds * 1e-6,
tz=tz)
```
We implemented a convert function that does exactly this, but we have
not been using it consistently yet. This commit replaces the last
occurances.
With that in mind, this commit changes:
* Consistently use the conversion function from the common repository
Fix start_time conversion imprecision bug
* Use shorter notations to set timezones
* Raise on invalid timezone in create()
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Makes it easier to handle & compare the request object with a dispatch object, also adds more consistency overall. Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Some tests require extra checks to not rely on the order. Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Round start_time seconds to have the same behavior as the gRPC server frequenz-io/frequenz-service-dispatch#77 Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
There is hardly any use-case for wanting to use `create()` and not have the new dispatch available. This is also in anticipation of the upcoming server-side feature that will return the newly created dispatch. Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
shsms
left a comment
There was a problem hiding this comment.
Just a couple of comments - no immediate action needed for one of them I think.
| Will try to return the created dispatch, identifying it by | ||
| the same fields as the request. |
There was a problem hiding this comment.
Maybe present tense is nicer, but you could also elaborate a bit on what "try" means:
| Will try to return the created dispatch, identifying it by | |
| the same fields as the request. | |
| Returns the created dispatch, if it can be identified using | |
| the same fields as the request. If not, raises an exception. |
There was a problem hiding this comment.
That's a fair suggestion, though given that we'll update this part soon, I think we can leave it for now.
| if key == "start_time": | ||
| value = rounded_start_time(value) | ||
|
|
||
| if not (found := getattr(dispatch, key) == value): |
There was a problem hiding this comment.
Since python 3.11 getattr can be much slower because they get in the way of the adaptive interpreter and other optimizations. It is too bad api.CreateDispatch doesn't return a dispatch ID, or the entire dispatch.
Won't be a bad idea to implement this in the api level, I think, so that you can avoid additional calls to list and then filter.
There was a problem hiding this comment.
Won't be a bad idea to implement this in the api level, I think, so that you can avoid additional calls to list and then filter.
That's all in the works, this is just to provide the feature before the API is ready. That way we can later add it and clients don't need to change.
The merge-base changed after approval.
|
Ok, LGTM then. |
The merge-base changed after approval.
The merge-base changed after approval.
|
Re-opeening as github seems very bugged now. |
|
Probably needs a rebase? |
is_{active,dry_run}.create()return the new created dispatch