-
Notifications
You must be signed in to change notification settings - Fork 55
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
[DEPRECATED PR] Create Timer Implementation #39
Closed
Closed
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
bf05733
create timer first pass
priyaananthasankar 71a5ad6
fix bugs to make waitForExternalEvent working
9177fe2
add waitforexternalevent samples
f55748f
minor fixes(variable name, delete comment)
406334d
flake8 fixes
8601b74
add docstrings
9b9af77
implement task_any function
2ed3d79
unittest for waitforexternalevents
6a2d066
fix bugs after merging dev
198e54f
fix flake8
eb47bc0
Base implementation of tests
scgbear 3e76499
parrot values success
scgbear 76fdcfc
test full complete flow
scgbear 3b2b68a
test failed scenario
scgbear 9d40be5
docstring to numpy format
f20a2e0
minor changes (rename, remove logging)
5d1115b
unittest for task_any, added tasks_test_utils
cb29fee
add class __eq__ function for Waitforexternalevent actions
abf0166
add samples readme doc
bd19b1c
fix flake8
12004fe
Refactoring HistoryEvent
scgbear c2fc638
add docstrings for HistoryEvent class
scgbear bf1e2e1
Refactor json conversion
scgbear a0fa70f
simple Fan out fan in sample
scgbear c0d8681
Fix flake errors
scgbear b927c04
Remove local debugging bits
scgbear 5b8b6d0
remove state in task_any
75010c3
add handle faulted task_any case +unittest
74305c3
Undo De Morgan's Law
scgbear 6ab0dc7
replace filters with list comprehension
scgbear 47f0cb8
Add documentation for tracking API implementation
scgbear 606e80a
move datetime format string to azure package
scgbear cba9740
replace filter with list comprehension
scgbear 77ee682
remove extra zimezone from format
scgbear 8509c39
Push context initialization our of handle method
scgbear 3c2ba43
able to pass in tasksets to task_any and task_all
db21a28
update unittest for adding timestamp to taskset, add unittest for pas…
580285f
fix bugs in task_all(when all tasks fail), and fix unittest for that …
2af63d5
fix flake8
77331d6
test from orchestrator level(draft)
ad82120
Remove IFunctionContext abstraction
scgbear ddcfc67
Starting of schema validation bits
scgbear 8950fe7
wire up schema validation into the orchestrator tests
scgbear 6cdba74
Test commit
scgbear 5d2957c
fix flake 8 issues
scgbear 8ca4aad
fix pytest, remove task_any_tests from orchestrator level
7673e16
fix flake8
f7a9af8
create timer first pass
priyaananthasankar 0955ce2
rebased
priyaananthasankar 060df32
rebased
priyaananthasankar d3ff8f9
rebased
priyaananthasankar 26fd2b4
Merge branch 'dev' into monitoring
priyaananthasankar 492e580
rebased
priyaananthasankar 2dc5de1
Merge branch 'monitoring' of https://github.com/priyaananthasankar/az…
priyaananthasankar 6121c6c
rebased
priyaananthasankar d3e9cab
rebased
priyaananthasankar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
42 changes: 42 additions & 0 deletions
42
azure/durable_functions/models/actions/CreateTimerAction.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import Any, Dict | ||
|
||
from .ActionType import ActionType | ||
from ..utils.json_utils import add_attrib,add_datetime_attrib | ||
import datetime | ||
|
||
class CreateTimerAction: | ||
|
||
""" | ||
Defines the structure of the Create Timer object. | ||
|
||
Returns | ||
------- | ||
Provides the information needed by the durable extension to be able to schedule the activity. | ||
|
||
Raises | ||
------ | ||
ValueError | ||
if the event fired is not of valid datetime object | ||
""" | ||
def __init__(self,fire_at: datetime,is_cancelled:bool=False): | ||
self.action_type : ActionType = ActionType.CREATE_TIMER | ||
self.fire_at:datetime = fire_at | ||
self.is_cancelled: bool = is_cancelled | ||
|
||
if not isinstance(self.fire_at,datetime.date): | ||
raise ValueError("fireAt: Expected valid datetime object but got ", self.fire_at) | ||
|
||
def to_json(self) -> Dict[str, Any]: | ||
""" | ||
Convert object into a json dictionary. | ||
|
||
Returns | ||
------- | ||
Dict[str, Any] | ||
The instance of the class converted into a json dictionary | ||
""" | ||
json_dict = {} | ||
add_attrib(json_dict, self, 'action_type', 'actionType') | ||
add_datetime_attrib(json_dict, self, 'fire_at', 'fireAt') | ||
add_attrib(json_dict, self, 'is_cancelled', 'isCanceled') | ||
return json_dict |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import List, Any | ||
from ..models.actions.CreateTimerAction import CreateTimerAction | ||
from ..models.history import HistoryEvent | ||
from .task_utilities import \ | ||
find_task_retry_timer_created, find_task_retry_timer_fired, set_processed | ||
import datetime | ||
from .timer_task import TimerTask | ||
|
||
def create_timer_task(state: List[HistoryEvent], | ||
fire_at: datetime) -> TimerTask: | ||
""" | ||
Durable Timers are used in orchestrator functions to implement delays or to | ||
setup timeouts on async actions. | ||
|
||
Parameters | ||
---------- | ||
state : List[HistoryEvent] | ||
The list of history events to search to determine the current state of the activity | ||
fire_at : datetime | ||
The time interval to fire the timer trigger | ||
|
||
Returns | ||
------- | ||
TimerTask | ||
A Durable Timer Task that schedules the timer to wake up the activity | ||
""" | ||
|
||
new_action = CreateTimerAction(fire_at) | ||
|
||
timer_created = find_task_retry_timer_created(state,fire_at) | ||
timer_fired = find_task_retry_timer_fired(state,timer_created) | ||
|
||
set_processed([timer_created,timer_fired]) | ||
|
||
if timer_fired: | ||
return TimerTask( | ||
is_completed=True, | ||
action=new_action, | ||
timestamp=timer_fired["Timestamp"], | ||
id_=timer_fired["TaskScheduledId"]) | ||
else: | ||
return TimerTask( | ||
is_completed=False, | ||
action=new_action, | ||
timestamp=None, | ||
id_=None) | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from ..models.Task import Task | ||
import datetime | ||
|
||
class TimerTask(Task): | ||
""" | ||
Returned from DurableOrchestrationContext.createTimer if the call | ||
is not 'yield-ed". Represents a pending timer. | ||
All pending timers must be completed or canceled for an orchestration | ||
to complete. | ||
|
||
Example: Cancel a timer | ||
``` | ||
timeout_task = context.df.create_timer(expiration_date) | ||
if not timeout_task.is_completed(): | ||
timeout_task.cancel() | ||
``` | ||
#TODO Write an example for create_timeout | ||
""" | ||
|
||
def __init__(self, action ,is_completed, timestamp, id_): | ||
self._action = action, | ||
self._is_completed = is_completed, | ||
self._timestamp = timestamp, | ||
self._id = id_ | ||
|
||
# Task( | ||
priyaananthasankar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# is_completed=self._is_completed, | ||
# is_faulted=False, | ||
# action=self._action, | ||
# result=None, | ||
# timestamp=self._timestamp, | ||
# id_=self._id) | ||
|
||
super().__init__(self._is_completed,False,self._action,None,self._timestamp,self._id,None) | ||
|
||
def is_cancelled() -> bool: | ||
""" | ||
Returns | ||
------- | ||
bool: Whether or not the timer has been cancelled | ||
|
||
""" | ||
return self._action.is_cancelled | ||
|
||
def cancel(): | ||
""" | ||
Indicates the timer should be cancelled. This request will execute on | ||
the next `yield` or `return` statement | ||
|
||
Raises | ||
------ | ||
ValueError | ||
Raises an error if the task is already completed and an attempt is made to cancel it | ||
""" | ||
if not self._is_completed: | ||
self._action.is_cancelled = True | ||
else: | ||
raise ValueError("Cannot cancel a completed task.") |
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.
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.
Looks like you're missing the lambda expression that pulls the input value out of the context string passed in. Also I've been separating the implementation of the functions from the context. Two reasons, 1. the functions aren't dependent on any of the class state, you'll get all sorts of squiggly lines all over this function in PyCharm wanting you to either mark it as a classmethod, or pull it out of the class. 2. separation of concerns, this functions can be tested without the DurableOrchestrationContext object created. This it is a small function all together, but I'd rather stick with the convention of separation. Helps the reader to know that they can look in the tasks package to see the actual implementation of all of the functions, instead of some in the tasks package, some directly implemented in the DurableOrchestrationContext module.
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.
agreed