Module: Jets::Event::Dsl::ScheduledEvent
- Includes:
- RateExpression
- Defined in:
- lib/jets/event/dsl/scheduled_event.rb
Instance Method Summary collapse
-
#cron(expression, props = {}) ⇒ Object
Public: Creates CloudWatch Event Rule.
- #normalize_cron_expression(expr) ⇒ Object
-
#rate(expression, props = {}) ⇒ Object
Public: Creates CloudWatch Event Rule.
-
#rule_event(props = {}) ⇒ Object
interface method.
- #scheduled_event(expression, props = {}) ⇒ Object
Methods included from RateExpression
Instance Method Details
#cron(expression, props = {}) ⇒ Object
Public: Creates CloudWatch Event Rule
expression - The cron expression.
Examples
cron("0 */12 * * ? *")
cron("0 */12 * * ? *", description: "Hard event")
31 32 33 34 |
# File 'lib/jets/event/dsl/scheduled_event.rb', line 31 def cron(expression, props = {}) expression = normalize_cron_expression(expression) scheduled_event("cron(#{expression})", props) end |
#normalize_cron_expression(expr) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/jets/event/dsl/scheduled_event.rb', line 36 def normalize_cron_expression(expr) parts = expr.split(" ") # AWS Cron expressions require ? for the day of the week field parts[-2] = "?" if parts[-2] == "*" parts.join(" ") end |
#rate(expression, props = {}) ⇒ Object
Public: Creates CloudWatch Event Rule
expression - The rate expression.
Examples
rate("10 minutes")
rate("10 minutes", description: "Hard event")
13 14 15 16 17 18 19 20 |
# File 'lib/jets/event/dsl/scheduled_event.rb', line 13 def rate(expression, props = {}) expression = rate_expression(expression) # normalize the rate expression md = expression.match(/\d+\s+\w+/) raise ArgumentError, "Invalid rate expression: #{expression}" unless md expression = "rate(#{expression})" scheduled_event(expression, props) end |
#rule_event(props = {}) ⇒ Object
interface method
49 50 51 |
# File 'lib/jets/event/dsl/scheduled_event.rb', line 49 def rule_event(props = {}) {} end |
#scheduled_event(expression, props = {}) ⇒ Object
43 44 45 46 |
# File 'lib/jets/event/dsl/scheduled_event.rb', line 43 def scheduled_event(expression, props = {}) props = props.merge(ScheduleExpression: expression) rule_event(props) end |