-
Notifications
You must be signed in to change notification settings - Fork 8
fix: time based state refresh for each activity #796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1d75391
76ab9fd
e3ec139
e4c2e07
54470ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| import os | ||
| from abc import ABC | ||
| from datetime import datetime, timedelta | ||
| from typing import Any, Dict, Generic, Optional, TypeVar | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
@@ -62,6 +63,7 @@ class ActivitiesState(BaseModel, Generic[HandlerType]): | |
| model_config = {"arbitrary_types_allowed": True} | ||
| handler: Optional[HandlerType] = None | ||
| workflow_args: Optional[Dict[str, Any]] = None | ||
| last_updated_timestamp: Optional[datetime] = None | ||
|
|
||
|
|
||
| ActivitiesStateType = TypeVar("ActivitiesStateType", bound=ActivitiesState) | ||
|
|
@@ -142,6 +144,15 @@ async def _get_state(self, workflow_args: Dict[str, Any]) -> ActivitiesStateType | |
| workflow_id = get_workflow_id() | ||
| if workflow_id not in self._state: | ||
| await self._set_state(workflow_args) | ||
|
|
||
| if workflow_id in self._state: | ||
| current_timestamp = datetime.now() | ||
| # if difference of current_timestamp and last_updated_timestamp is greater than 15 minutes, then again _set_state | ||
| last_updated = self._state[workflow_id].last_updated_timestamp | ||
| if last_updated and current_timestamp - last_updated > timedelta( | ||
| minutes=15 | ||
| ): | ||
| await self._set_state(workflow_args) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: BugThe Additional Locations (1)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @abhishekagrawal-atlan please take a loo |
||
| return self._state[workflow_id] | ||
| except OrchestratorError as e: | ||
abhishekagrawal-atlan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| logger.error( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please put this under an else block