MCPcopy Index your code
hub / github.com/zappa/Zappa / schedule

Method schedule

zappa/cli.py:1439–1514  ·  view source on GitHub ↗

Given a a list of functions and a schedule to execute them, setup up regular execution.

(self)

Source from the content-addressed store, hash-verified

1437 self.zappa.update_cognito(self.lambda_name, user_pool, lambda_configs, self.lambda_arn)
1438
1439 def schedule(self):
1440 """
1441 Given a a list of functions and a schedule to execute them,
1442 setup up regular execution.
1443 """
1444 events = self.stage_config.get("events", [])
1445
1446 if events:
1447 if not isinstance(events, list): # pragma: no cover
1448 print("Events must be supplied as a list.")
1449 return
1450
1451 for event in events:
1452 self.collision_warning(event.get("function"))
1453
1454 if self.stage_config.get("keep_warm", True):
1455 if not events:
1456 events = []
1457
1458 keep_warm_rate = self.stage_config.get("keep_warm_expression", "rate(4 minutes)")
1459 events.append(
1460 {
1461 "name": "zappa-keep-warm",
1462 "function": "handler.keep_warm_callback",
1463 "expression": keep_warm_rate,
1464 "description": "Zappa Keep Warm - {}".format(self.lambda_name),
1465 }
1466 )
1467
1468 if events:
1469 try:
1470 function_response = self.zappa.lambda_client.get_function(FunctionName=self.lambda_name)
1471 except botocore.exceptions.ClientError: # pragma: no cover
1472 click.echo(
1473 click.style("Function does not exist", fg="yellow")
1474 + ", please "
1475 + click.style("deploy", bold=True)
1476 + "first. Ex:"
1477 + click.style("zappa deploy {}.".format(self.api_stage), bold=True)
1478 )
1479 sys.exit(-1)
1480
1481 print("Scheduling..")
1482 self.zappa.schedule_events(
1483 lambda_arn=function_response["Configuration"]["FunctionArn"],
1484 lambda_name=self.lambda_name,
1485 events=events,
1486 )
1487
1488 # Add async tasks SNS
1489 if self.stage_config.get("async_source", None) == "sns" and self.stage_config.get("async_resources", True):
1490 self.lambda_arn = self.zappa.get_lambda_function(function_name=self.lambda_name)
1491 topic_arn = self.zappa.create_async_sns_topic(lambda_name=self.lambda_name, lambda_arn=self.lambda_arn)
1492 click.echo("SNS Topic created: %s" % topic_arn)
1493
1494 # Add async tasks DynamoDB
1495 table_name = self.stage_config.get("async_response_table", False)
1496 read_capacity = self.stage_config.get("async_response_table_read_capacity", 1)

Callers 4

dispatch_commandMethod · 0.95
deployMethod · 0.95
updateMethod · 0.95
test_cli_awsMethod · 0.95

Calls 5

collision_warningMethod · 0.95
schedule_eventsMethod · 0.80
get_lambda_functionMethod · 0.80

Tested by 1

test_cli_awsMethod · 0.76