Add setex support on set_state method (and fix tests)#44
Draft
Add setex support on set_state method (and fix tests)#44
setex support on set_state method (and fix tests)#44Conversation
marianobrc
reviewed
Jan 13, 2025
Comment on lines
23
to
30
| async def set_state(self, integration_id: str, action_id: str, state: dict, source_id: str = "no-source"): | ||
| for attempt in stamina.retry_context(on=redis.RedisError, attempts=5, wait_initial=1.0, wait_max=30, wait_jitter=3.0): | ||
| with attempt: | ||
| await self.db_client.set( | ||
| await self.db_client.setex( | ||
| f"integration_state.{integration_id}.{action_id}.{source_id}", | ||
| 7*86400, | ||
| json.dumps(state, default=str) | ||
| ) |
Collaborator
There was a problem hiding this comment.
I see that in some integrations we want the state data to expire. It'd be better to make that feature optional and let the caller choose whether to use it. We could add a "ttl" or "expiration" param defaulting to None. Then when set we use setex, else we use set. Then update the integrations needing this to set the ttl.
Contributor
There was a problem hiding this comment.
The arguments for set include , ex: Union[int, datetime.timedelta, NoneType] = None so we can continue using the same generalized set method.
set(name: Union[bytes, str, memoryview], value: Union[bytes, memoryview, str, int, float], ex: Union[int, datetime.timedelta, NoneType] = None, ...)
marianobrc
requested changes
Jan 13, 2025
Collaborator
marianobrc
left a comment
There was a problem hiding this comment.
Thanks for proposing this @vgarcia13 . I added a comment about making this feature optional for more flexibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.