Skip to content

Add setex support on set_state method (and fix tests)#44

Draft
vgarcia13 wants to merge 1 commit intomainfrom
fix-state-tests
Draft

Add setex support on set_state method (and fix tests)#44
vgarcia13 wants to merge 1 commit intomainfrom
fix-state-tests

Conversation

@vgarcia13
Copy link
Copy Markdown
Contributor

No description provided.

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)
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, ...)

Copy link
Copy Markdown
Collaborator

@marianobrc marianobrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for proposing this @vgarcia13 . I added a comment about making this feature optional for more flexibility.

@vgarcia13 vgarcia13 marked this pull request as draft January 13, 2025 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants