Sha256: 1ee907e5b4dd7b4a80539d42125b6724860860cc56485f19d236226be57a110d

Contents?: true

Size: 1.37 KB

Versions: 9

Compression:

Stored size: 1.37 KB

Contents

class Fanforce::AppWorker

  LOADED_AT = Time.now

  @@iron = {}
  @@redis = {}
  @@log = Logger.new($stdout)

  def self.iron_token
    @@iron[:token] || ENV['IRON_TOKEN']
  end

  def self.iron_project_id
    @@iron[:project_id] || ENV['IRON_PROJECT_ID']
  end

  def self.iron_mq
    require 'iron_mq'
    @@iron[:mq] ||= IronMQ::Client.new(:token => @@iron[:token], :project_id => @@iron[:project_id])
  end

  def self.redis_url_errorlog
    @@redis[:url_errorlog] || ENV['REDIS_URL_ERRORLOG'] || (raise 'No REDIS_URL_ERRORLOG found in ENV')
  end

  def self.set_config(obj)
    @@iron[:token] = obj[:iron_token] if obj[:iron_token]
    @@iron[:project_id] = obj[:iron_project_id] if obj[:iron_project_id]
    @@redis[:url_errorlog] = obj[:redis_url_errorlog] if obj[:redis_url_errorlog]
  end

  def self.log
    @@log
  end

  ##########################################################################################

  def self.enqueue(queue_id, params, options={})
    raise 'Params being sent to the queue must be a Hash' if !params.is_a?(Hash)

    queue_id = Utils.iron_queue_id(queue_id)
    retries = (options[:retries].present?) ? options.delete(:retries) : 0
    iron_mq.queue(queue_id).post({params: params, retries: retries}.to_json, options)
  end

  def self.run(worker_data, min_execution_time=300, &code_block)
    Runner.new(worker_data, min_execution_time, &code_block)
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fanforce-app-worker-1.1.0.rc5 lib/fanforce/app_worker/worker.rb
fanforce-app-worker-1.1.0.rc4 lib/fanforce/app_worker/worker.rb
fanforce-app-worker-1.1.0.rc3 lib/fanforce/app_worker/worker.rb
fanforce-app-worker-1.1.0.rc2 lib/fanforce/app_worker/worker.rb
fanforce-app-worker-1.1.0.rc1 lib/fanforce/app_worker/worker.rb
fanforce-app-worker-1.0.3 lib/fanforce/app_worker/worker.rb
fanforce-app-worker-1.0.2 lib/fanforce/app_worker/worker.rb
fanforce-app-worker-1.0.1 lib/fanforce/app_worker/worker.rb
fanforce-app-worker-1.0.0 lib/fanforce/app_worker/worker.rb