Sha256: cd88a67b9a6d895d67409a06d5f3f822c844ed8c97b43556f5d32a92f13b2bc0

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Stenotype
  module ContextHandlers
    #
    # A namespace containing extension of rails components
    # for fetching specific data from those components.
    # For example fetching request from a controller context,
    # or fetching ActiveJob attributes from an ActiveJob instance
    #
    module Rails
      #
      # ActiveJob handler to support fetching data out of an ActiveJob instance
      #
      class ActiveJob < Stenotype::ContextHandlers::Base
        self.handler_name = :active_job

        #
        # @todo How to deal with _args? It won't necessarily respond to #as_json
        # @return {Hash} a JSON representation of job's data
        #
        def as_json(*_args)
          {
            job_id: job_id,
            enqueued_at: Time.now,
            queue_name: queue_name,
            class: context.class.name
          }
        end

        private

        def job_id
          context.job_id
        end

        def queue_name
          context.queue_name
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stenotype-0.1.0 lib/stenotype/context_handlers/rails/active_job.rb