Skip to content

Commit 3a17e5a

Browse files
committed
changes for code review
And reformatted with Black
1 parent b244baa commit 3a17e5a

File tree

5 files changed

+72
-33
lines changed

5 files changed

+72
-33
lines changed

python/example_code/scheduler/hello/hello_scheduler.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ def hello_scheduler(scheduler_client):
1616
the low-level Amazon EventBridge Scheduler service API.
1717
"""
1818
print("Hello, Amazon EventBridge Scheduler! Let's list some of your schedules:\n")
19-
paginator = scheduler_client.get_paginator('list_schedules')
20-
page_iterator = paginator.paginate(PaginationConfig={'MaxItems':10})
19+
paginator = scheduler_client.get_paginator("list_schedules")
20+
page_iterator = paginator.paginate(PaginationConfig={"MaxItems": 10})
2121

2222
schedule_names: [str] = []
2323
for page in page_iterator:
24-
for schedule in page['Schedules']:
25-
schedule_names.append(schedule['Name'])
24+
for schedule in page["Schedules"]:
25+
schedule_names.append(schedule["Name"])
2626

2727
print(f"{len(schedule_names)} schedule(s) retrieved.")
2828
for schedule_name in schedule_names:
2929
print(f"\t{schedule_name}")
3030

31+
3132
if __name__ == "__main__":
3233
hello_scheduler(boto3.client("scheduler"))
33-
# snippet-end:[python.example_code.scheduler.Hello]
34+
# snippet-end:[python.example_code.scheduler.Hello]
54.9 KB
Loading

python/example_code/scheduler/scenario/scheduler_scenario.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import demo_tools.question as q
2727

2828

29-
30-
3129
DASHES = "-" * 80
3230

3331
sys.path
@@ -76,7 +74,10 @@ def run(self) -> None:
7674
print(DASHES)
7775

7876
print(DASHES)
79-
if q.ask("Do you want to delete all resources created by this workflow? (y/n) ", q.is_yesno):
77+
if q.ask(
78+
"Do you want to delete all resources created by this workflow? (y/n) ",
79+
q.is_yesno,
80+
):
8081
self.cleanup()
8182
print(DASHES)
8283

@@ -122,8 +123,12 @@ def prepare_application(self) -> None:
122123
print(f"Stack output RoleARN: {self.role_arn}")
123124
print(f"Stack output SNStopicARN: a")
124125
schedule_group_name = "workflow-schedules-group"
125-
schedule_group_arn = self.eventbridge_scheduler.create_schedule_group(schedule_group_name)
126-
print(f"Successfully created schedule group '{self.schedule_group_name}': {schedule_group_arn}.")
126+
schedule_group_arn = self.eventbridge_scheduler.create_schedule_group(
127+
schedule_group_name
128+
)
129+
print(
130+
f"Successfully created schedule group '{self.schedule_group_name}': {schedule_group_arn}."
131+
)
127132
self.schedule_group_name = schedule_group_name
128133
print("Application preparation complete.")
129134

@@ -151,20 +156,23 @@ def create_one_time_schedule(self) -> None:
151156
delete_after_completion=True,
152157
use_flexible_time_window=True,
153158
)
154-
print(f"Successfully created schedule '{schedule_name}' in schedule group 'workflow-schedules-group': {schedule_arn}.")
159+
print(
160+
f"Successfully created schedule '{schedule_name}' in schedule group 'workflow-schedules-group': {schedule_arn}."
161+
)
155162
print(f"Subscription email will receive an email from this event.")
156163
print(f"You must confirm your subscription to receive event emails.")
157164
print(f"One-time schedule '{schedule_name}' created successfully.")
158165

159-
160166
def create_recurring_schedule(self) -> None:
161167
"""
162168
Create a recurring schedule to send events at a specified rate in minutes.
163169
"""
164170

165-
print("Creating a recurring schedule to send events for one hour...");
166-
schedule_name = q.ask("Enter a name for the recurring schedule: ");
167-
schedule_rate_in_minutes = q.ask("Enter the desired schedule rate (in minutes): ", q.is_int);
171+
print("Creating a recurring schedule to send events for one hour...")
172+
schedule_name = q.ask("Enter a name for the recurring schedule: ")
173+
schedule_rate_in_minutes = q.ask(
174+
"Enter the desired schedule rate (in minutes): ", q.is_int
175+
)
168176

169177
schedule_arn = self.eventbridge_scheduler.create_schedule(
170178
schedule_name,
@@ -175,12 +183,18 @@ def create_recurring_schedule(self) -> None:
175183
f"Recurrent event test from schedule {schedule_name}.",
176184
)
177185

178-
print(f"Successfully created schedule '{schedule_name}' in schedule group 'workflow-schedules-group': {schedule_arn}.")
179-
print(f"Subscription email will receive an email from this event.");
180-
print(f"You must confirm your subscription to receive event emails.");
186+
print(
187+
f"Successfully created schedule '{schedule_name}' in schedule group 'workflow-schedules-group': {schedule_arn}."
188+
)
189+
print(f"Subscription email will receive an email from this event.")
190+
print(f"You must confirm your subscription to receive event emails.")
181191

182-
if q.ask(f"Are you ready to delete the '{schedule_name}' schedule? (y/n)", q.is_yesno) :
183-
self.eventbridge_scheduler.delete_schedule(schedule_name, self.schedule_group_name)
192+
if q.ask(
193+
f"Are you ready to delete the '{schedule_name}' schedule? (y/n)", q.is_yesno
194+
):
195+
self.eventbridge_scheduler.delete_schedule(
196+
schedule_name, self.schedule_group_name
197+
)
184198

185199
def deploy_cloudformation_stack(
186200
self, stack_name: str, cfn_template: str, parameters: [dict[str, str]]
@@ -220,7 +234,9 @@ def destroy_cloudformation_stack(self, stack: ServiceResource) -> None:
220234
221235
:param stack: The CloudFormation stack that manages the example resources.
222236
"""
223-
print(f"CloudFormation stack '{stack.name}' is being deleted. This may take a few minutes.")
237+
print(
238+
f"CloudFormation stack '{stack.name}' is being deleted. This may take a few minutes."
239+
)
224240
stack.delete()
225241
waiter = self.cloud_formation_resource.meta.client.get_waiter(
226242
"stack_delete_complete"
@@ -269,4 +285,4 @@ def get_template_as_string() -> str:
269285
if demo is not None:
270286
demo.cleanup()
271287

272-
# snippet-end:[python.example_code.scheduler.FeatureScenario]
288+
# snippet-end:[python.example_code.scheduler.FeatureScenario]

python/example_code/scheduler/scenario/test/conftest.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@
2727

2828

2929
class ScenarioData:
30-
def __init__(self, scheduler_client, cloud_formation_resource, scheduler_stubber, cloud_formation_stubber):
30+
def __init__(
31+
self,
32+
scheduler_client,
33+
cloud_formation_resource,
34+
scheduler_stubber,
35+
cloud_formation_stubber,
36+
):
3137
self.scheduler_client = scheduler_client
32-
self.cloud_formation_resource= cloud_formation_resource
38+
self.cloud_formation_resource = cloud_formation_resource
3339
self.scheduler_stubber = scheduler_stubber
3440
self.cloud_formation_stubber = cloud_formation_stubber
3541
self.scenario = scheduler_scenario.SchedulerScenario(
3642
scheduler_wrapper=SchedulerWrapper(self.scheduler_client),
37-
cloud_formation_resource=self.cloud_formation_resource,
43+
cloud_formation_resource=self.cloud_formation_resource,
3844
)
3945

4046

@@ -44,8 +50,14 @@ def scenario_data(make_stubber):
4450
scheduler_stubber = make_stubber(scheduler_client)
4551
cloud_formation_resource = boto3.resource("cloudformation")
4652
cloud_formation_stubber = make_stubber(cloud_formation_resource.meta.client)
47-
return ScenarioData(scheduler_client, cloud_formation_resource, scheduler_stubber, cloud_formation_stubber)
53+
return ScenarioData(
54+
scheduler_client,
55+
cloud_formation_resource,
56+
scheduler_stubber,
57+
cloud_formation_stubber,
58+
)
59+
4860

4961
@pytest.fixture
5062
def mock_wait(monkeypatch):
51-
return
63+
return

python/example_code/scheduler/scheduler_wrapper.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def __init__(self, eventbridge_scheduler_client: client):
2626
@classmethod
2727
def from_client(cls) -> "SchedulerWrapper":
2828
"""
29-
Creates a SchedulerWrapper instance with a default EventBridge client.
29+
Creates a SchedulerWrapper instance with a default EventBridge Scheduler client.
3030
31-
:return: An instance of SchedulerWrapper initialized with the default EventBridge client.
31+
:return: An instance of SchedulerWrapper initialized with the default EventBridge Scheduler client.
3232
"""
3333
eventbridge_scheduler_client = boto3.client("scheduler")
3434
return cls(eventbridge_scheduler_client)
@@ -94,7 +94,9 @@ def create_schedule(
9494
err.response["Error"]["Message"],
9595
)
9696
else:
97-
logger.error("Error creating schedule: %s", err.response["Error"]["Message"])
97+
logger.error(
98+
"Error creating schedule: %s", err.response["Error"]["Message"]
99+
)
98100
raise
99101

100102
# snippet-end:[python.example_code.scheduler.CreateSchedule]
@@ -119,7 +121,9 @@ def delete_schedule(self, name: str, schedule_group_name: str) -> None:
119121
err.response["Error"]["Message"],
120122
)
121123
else:
122-
logger.error("Error deleting schedule: %s", err.response["Error"]["Message"])
124+
logger.error(
125+
"Error deleting schedule: %s", err.response["Error"]["Message"]
126+
)
123127
raise
124128

125129
# snippet-end:[python.example_code.scheduler.DeleteSchedule]
@@ -145,7 +149,10 @@ def create_schedule_group(self, name: str) -> str:
145149
err.response["Error"]["Message"],
146150
)
147151
else:
148-
logger.error("Error creating schedule group: %s", err.response["Error"]["Message"])
152+
logger.error(
153+
"Error creating schedule group: %s",
154+
err.response["Error"]["Message"],
155+
)
149156
raise
150157

151158
# snippet-end:[python.example_code.scheduler.CreateScheduleGroup]
@@ -168,7 +175,10 @@ def delete_schedule_group(self, name: str) -> None:
168175
err.response["Error"]["Message"],
169176
)
170177
else:
171-
logger.error("Error deleting schedule group: %s", err.response["Error"]["Message"])
178+
logger.error(
179+
"Error deleting schedule group: %s",
180+
err.response["Error"]["Message"],
181+
)
172182
raise
173183
# snippet-end:[python.example_code.scheduler.DeleteScheduleGroup]
174184

0 commit comments

Comments
 (0)