Sha256: 74729e0ac19bd6d02b5757326873a2eb6f5a10ef8bc998b6c42ea099744ca782

Contents?: true

Size: 1.57 KB

Versions: 13

Compression:

Stored size: 1.57 KB

Contents

require 'delorean_lang'

class Marty::PromiseJob < Struct.new(:promise,
                                     :title,
                                     :sname,
                                     :tag,
                                     :node,
                                     :params,
                                     :attrs,
                                     :hook,
                                    )
  # def log(msg)
  #   open('/tmp/dj.out', 'a') { |f| f.puts msg }
  # end
  #
  def enqueue(job)
    config = Rails.configuration.marty
    hooks = config.promise_job_enqueue_hooks

    return if hooks.blank?

    hooks.each do |hook|
      hook.call(job)
    end
  end

  def perform
    # log "PERF #{Process.pid} #{title}"

    promise.set_start

    begin
      # in case the job writes to the the database
      Mcfly.whodunnit = promise.user

      engine = Marty::ScriptSet.new(tag).get_engine(sname)

      attrs_eval = engine.evaluate(node, attrs, params)
      res = attrs.zip(attrs_eval).each_with_object({}) do |(attr, val), h|
        h[attr] = val
      end

      # log "DONE #{Process.pid} #{promise.id} #{Time.now.to_f} #{res}"
    rescue StandardError => e
      res = Delorean::Engine.grok_runtime_exception(e)
      # log "ERR- #{Process.pid} #{promise.id} #{Time.now.to_f} #{e}"
    end
    promise.set_result(res)
    process_hook(res)
  end

  def process_hook(res)
      return unless hook

      hook.run(params: params, result: res)
  rescue StandardError => e
      Marty::Util.logger.error "promise hook failed: #{e}"
  end

  def max_attempts
    1
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
marty-8.5.0 lib/marty/promise_job.rb
marty-8.4.1 lib/marty/promise_job.rb
marty-8.3.1 lib/marty/promise_job.rb
marty-8.2.0 lib/marty/promise_job.rb
marty-8.0.0 lib/marty/promise_job.rb
marty-6.1.0 lib/marty/promise_job.rb
marty-5.2.0 lib/marty/promise_job.rb
marty-5.1.4 lib/marty/promise_job.rb
marty-5.1.3 lib/marty/promise_job.rb
marty-5.1.2 lib/marty/promise_job.rb
marty-5.1.1 lib/marty/promise_job.rb
marty-5.1.0 lib/marty/promise_job.rb
marty-3.1.0 lib/marty/promise_job.rb