Sha256: 414c81f523e375b20c7a8b6062b261017b9a66fa8d51b8b11846fce7451738eb

Contents?: true

Size: 1.88 KB

Versions: 21

Compression:

Stored size: 1.88 KB

Contents

class Jets::Cfn::TemplateBuilders
  class JobBuilder < BaseChildBuilder
    def compose
      add_common_parameters
      add_functions
      add_scheduled_tasks
    end

    def add_scheduled_tasks
      # @app_klass is PostsController, HardJob, Hello, or HelloFunction
      @app_klass.tasks.each do |task|
        map = Jets::Cfn::TemplateMappers::EventsRuleMapper.new(task)

        # If there's no scheduled expression dont add a scheduled Events::Rule
        if task.schedule_expression
          add_event_rule(task, map)
          add_permission(map)
        end
      end
    end

    def add_event_rule(task, map)
      add_resource(map.logical_id, "AWS::Events::Rule",
        ScheduleExpression: task.schedule_expression,
        State: task.state,
        Targets: [
          {
            Arn: "!GetAtt #{map.lambda_function_logical_id}.Arn",
            Id: map.rule_target_id
          }
        ]
      )
      # Example:
      # add_resource("HardJobDigScheduledEvent", "AWS::Events::Rule",
      #   ScheduleExpression: "rate(1 minute)",
      #   State: "ENABLED",
      #   Targets: [
      #     {
      #       Arn: "!GetAtt HardJobDigLambdaFunction.Arn",
      #       Id: "RuleTargetHardJobDig"
      #     }
      #   ]
      # )
    end

    def add_permission(map)
      add_resource(map.permission_logical_id, "AWS::Lambda::Permission",
        FunctionName: "!GetAtt #{map.lambda_function_logical_id}.Arn",
        Action: "lambda:InvokeFunction",
        Principal: "events.amazonaws.com",
        SourceArn: "!GetAtt #{map.logical_id}.Arn"
      )
      # Example:
      # add_resource("HardJobDigEventsRulePermission", "AWS::Lambda::Permission",
      #   FunctionName: "!GetAtt HardJobDigLambdaFunction.Arn",
      #   Action: "lambda:InvokeFunction",
      #   Principal: "events.amazonaws.com",
      #   SourceArn: "!GetAtt HardJobDigScheduledEvent.Arn"
      # )
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
jets-0.7.1 lib/jets/cfn/template_builders/job_builder.rb
jets-0.7.0 lib/jets/cfn/template_builders/job_builder.rb
jets-0.6.9 lib/jets/cfn/template_builders/job_builder.rb
jets-0.6.8 lib/jets/cfn/template_builders/job_builder.rb
jets-0.6.7 lib/jets/cfn/template_builders/job_builder.rb
jets-0.6.6 lib/jets/cfn/template_builders/job_builder.rb
jets-0.6.5 lib/jets/cfn/template_builders/job_builder.rb
jets-0.6.4 lib/jets/cfn/template_builders/job_builder.rb
jets-0.6.3 lib/jets/cfn/template_builders/job_builder.rb
jets-0.6.2 lib/jets/cfn/template_builders/job_builder.rb
jets-0.6.1 lib/jets/cfn/template_builders/job_builder.rb
jets-0.6.0 lib/jets/cfn/template_builders/job_builder.rb
jets-0.5.8 lib/jets/cfn/template_builders/job_builder.rb
jets-0.5.7 lib/jets/cfn/template_builders/job_builder.rb
jets-0.5.6 lib/jets/cfn/template_builders/job_builder.rb
jets-0.5.5 lib/jets/cfn/template_builders/job_builder.rb
jets-0.5.4 lib/jets/cfn/template_builders/job_builder.rb
jets-0.5.3 lib/jets/cfn/template_builders/job_builder.rb
jets-0.5.2 lib/jets/cfn/template_builders/job_builder.rb
jets-0.5.1 lib/jets/cfn/template_builders/job_builder.rb