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
Add support for scheduled events #393
Conversation
Codecov Report
@@ Coverage Diff @@
## master #393 +/- ##
==========================================
+ Coverage 92.28% 92.75% +0.47%
==========================================
Files 18 18
Lines 2464 2569 +105
Branches 323 334 +11
==========================================
+ Hits 2274 2383 +109
+ Misses 141 137 -4
Partials 49 49
Continue to review full report at Codecov.
|
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 good. Just some early feedback on the user interface to start before I get into the deployer part of the code.
|
||
class CloudWatchEvent(object): | ||
def __init__(self, event_dict): | ||
self.version = event_dict['version'] |
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.
Will all of these be guaranteed to be present in the event? If it is a direct lookup and a key is missing from the event it would cause issues.
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.
Yes.
@@ -765,3 +779,82 @@ class AuthRoute(object): | |||
def __init__(self, path, methods): | |||
self.path = path | |||
self.methods = methods | |||
|
|||
|
|||
class EventSource(object): |
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.
I think the name EventSource
along with Chalice.event_sources
may be a bit ambiguous here because event source (thinking from the lambda perspective) could mean any event from any service as show by their docs but this seems to be specific to cloud watch events. We may want to either make the name more specific to cloudwatch event sources or make this class more generalized for any lambda event source (like repurpose the schedule_expression
to something general to lambda event sources).
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.
It's intentional to have an EventSource
type. The idea would be this is used for all event types as support more types is added. I don't envision adding a new public attr to chalice.Chalice
for every new event source, that wouldn't be maintainable. I can extract out a separate CloudWatchEventSource
class with EventSource
as its base type. Seemed like overkill for now, but I don't mind adding it.
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.
Makes sense. I like the idea of having EventSource
be the base class and CloudWatchEventSource
subclass from it to include any of the cloudwatch event specific logic.
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.
I pushed an update. Let me know what you think.
chalice/app.pyi
Outdated
|
||
|
||
class Rate(ScheduleExpression): | ||
unit = ... # type: str |
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.
The type here should be an integer. Or union of str and integer to be similar to Cron
? I think I would prefer integer though if you can only provide whole numbers to rate.
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.
That should be an integer, I'll update.
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 good. Just had a couple more comments. I think we should be good once we have docs up.
tests/functional/test_awsclient.py
Outdated
'AWS:SourceArn': source_arn, | ||
} | ||
}, | ||
'Effect': 'Allow', |
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.
Without looking at what got removed in the diff, it is not very easy to tell what portion of the policy needs to be present for it to be skipped. Maybe separate this into tests where one tests that a specific policy entry skips over the add_permission
call but the other entries causes add_permission
to be triggered?
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.
I refactored the test a bit to make this more clear.
return 'rate(%s %s)' % (self.value, unit) | ||
|
||
|
||
class Cron(ScheduleExpression): |
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.
Did we want to add Cron
and Rate
to the __init__
?
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.
I don't follow what you're asking. Can you elaborate?
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.
Oh so I have to import those two from chalice.app
right now, but I'm use to importing all of the user facing classes from chalice
instead when I right my application.
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.
ohhhh, chalice/__init__.py
. Gotcha. Yeah I can add that.
Cool. Looks good once docs are included, it should be good to merge. I also noticed that there was some missing coverage according to the codecov report. Do you know what that may be? |
Yeah it was some of the new code I added for the base class refactoring. I added a |
OK I think everything has been addressed, and docs have been added. Let me know if there's any more feedback. |
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 good. Just had a small comment. Otherwise, 🚢
docs/source/api.rst
Outdated
.. code-block:: python | ||
|
||
@app.schedule('cron(15 10 ? * 6L 2002-2005)') | ||
def handler(event): |
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.
We may want to have all of these handler names share the function name handler()
just in case if someone tries to literally copy and paste all of this. Maybe make these handler names more specific like cron_handler()
?
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.
You mean not share?
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.
yes not share
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.
OK I'll update that before merging.
Defines the API a user would interact with to configure and invoke scheduled events in their chalice app.
Proposal: #390
Sample app:
The implementation piggy backs off of the multi lambda support from the built in authorizers. The only unexpected change was an update to the deployed.json file from:
to:
So we can differentiate the different types of lambda functions.
The other caveat is that right now you still need to deploy an API gateway API. There isn't support yet for only deploying scheduled events. That will be in a follow up PR.
Review Notes
The deployer module has some duplication that I'm working on removing. The logic itself won't change but I'm refactoring the code. Everything else (
app.py
,awsclient.py
, all the tests) are ready for review.