Sha256: a9cf0dc1e68ceb872e4137ed488f6626fda7f20b40b6472296e84bc1f2ac42f1

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Ductr
  #
  # The base class for any job, you can use it directly if you don't need an ETL job.
  #
  class Job < ActiveJob::Base
    extend Annotable
    extend Forwardable

    include JobStatus

    # @return [Exception] The occurred error if any
    attr_reader :error
    # @return [Symbol] The job's status, one of `:queued`, `:working`, `:completed` and `:failed`
    attr_reader :status

    queue_as :ductr_jobs

    #
    # The active job's perform method. DO NOT override it, implement the #run method instead.
    #
    # @return [void]
    #
    def perform(*_)
      run
    end

    #
    # The configured adapter instances.
    #
    # @param [Symbol] name The adapter name
    #
    # @return [Adapter] The adapter corresponding to the given name
    #
    def adapter(name)
      Ductr.config.adapter(name)
    end

    #
    # The job's logger instance.
    #
    # @return [Ductr::Log::Logger] The logger instance
    #
    def logger
      @logger ||= Ductr.config.logging.new(self.class)
    end

    #
    # The entry point of jobs.
    #
    # @return [void]
    #
    def run
      raise NotImplementedError, "A job must implement the `#run` method"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ductr-0.2.3 lib/ductr/job.rb
ductr-0.2.2 lib/ductr/job.rb
ductr-0.2.1 lib/ductr/job.rb
ductr-0.2.0 lib/ductr/job.rb
ductr-0.1.2 lib/ductr/job.rb
ductr-0.1.1 lib/ductr/job.rb
ductr-0.1.0 lib/ductr/job.rb