Sha256: 6afb11a132fdd51bdca5f98ea4ffd58e5ff44b81ff6b80bb5a8b9604eb9f789e

Contents?: true

Size: 880 Bytes

Versions: 4

Compression:

Stored size: 880 Bytes

Contents

module Asynchronic
  class Job

    def self.queue(name=nil)
      name ? @queue = name : @queue
    end

    def self.enqueue(params={})
      process = Asynchronic.environment.create_process self, params
      process.enqueue
      process.id
    end

    def initialize(process)
      @process = process
    end

    def params
      process.params
    end

    def result(reference)
      process[reference].result
    end

    private

    attr_reader :process

    def async(type, params={})
      process.nest type, params
      nil
    end

    def get(key)
      process.get key
    end

    def set(key, value)
      process.set key, value
    end

    def retry_when(exceptions, interval=1)
      yield
    rescue *exceptions => ex
      Asynchronic.logger.error(self.class) { "Retry for: #{ex.class} #{ex.message}" }
      sleep interval
      retry
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
asynchronic-4.0.3 lib/asynchronic/job.rb
asynchronic-4.0.2 lib/asynchronic/job.rb
asynchronic-4.0.1 lib/asynchronic/job.rb
asynchronic-4.0.0 lib/asynchronic/job.rb