Sha256: d6d1e1c969d6c087f9bc1edcf49fd04e082b0c7fa8ef8d036a9f75aa2379e920

Contents?: true

Size: 1.52 KB

Versions: 20

Compression:

Stored size: 1.52 KB

Contents

require 'json'

# Job public methods get turned into Lambda functions.
#
# Jets::Job::Base < Jets::Lambda::Functions
# Both Jets::Job::Base and Jets::Lambda::Functions have Dsl modules included.
# So the Jets::Job::Dsl overrides some of the Jets::Lambda::Functions behavior.
module Jets::Job
  class Base < Jets::Lambda::Functions
    include Dsl

    # non-DSL methods
    include Helpers::KinesisEventHelper
    include Helpers::LogEventHelper
    include Helpers::S3EventHelper
    include Helpers::SnsEventHelper
    include Helpers::SqsEventHelper

    # Tracks bucket each time an s3_event is declared
    # Map of bucket_name => stack_name (nested part)
    cattr_accessor :s3_events # dont want this to be inheritable intentionally
    self.s3_events = {}

    class << self
      def process(event, context, meth)
        job = new(event, context, meth)
        job.send(meth)
      end

      def perform_now(meth, event={}, context={})
        new(event, context, meth).send(meth)
      end

      def perform_later(meth, event={}, context={})
        if on_lambda?
          function_name = "#{self.to_s.underscore}-#{meth}"
          call = Jets::Commands::Call.new(function_name, JSON.dump(event), invocation_type: "Event")
          call.run
        else
          puts "INFO: Not on AWS Lambda. In local mode perform_later executes the job with perform_now instead."
          perform_now(meth, event, context)
        end
      end

    private
      def on_lambda?
        !!ENV['AWS_LAMBDA_FUNCTION_NAME']
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
jets-4.0.12 lib/jets/job/base.rb
jets-4.0.11 lib/jets/job/base.rb
jets-4.0.10 lib/jets/job/base.rb
jets-4.0.9 lib/jets/job/base.rb
jets-4.0.8 lib/jets/job/base.rb
jets-4.0.7 lib/jets/job/base.rb
jets-4.0.6 lib/jets/job/base.rb
jets-4.0.5 lib/jets/job/base.rb
jets-4.0.4 lib/jets/job/base.rb
jets-4.0.3 lib/jets/job/base.rb
jets-4.0.2 lib/jets/job/base.rb
jets-4.0.1 lib/jets/job/base.rb
jets-4.0.0 lib/jets/job/base.rb
jets-3.2.2 lib/jets/job/base.rb
jets-3.2.1 lib/jets/job/base.rb
jets-3.2.0 lib/jets/job/base.rb
jets-3.1.5 lib/jets/job/base.rb
jets-3.1.4 lib/jets/job/base.rb
jets-3.1.3 lib/jets/job/base.rb
jets-3.1.2 lib/jets/job/base.rb