Sha256: e867bc5ebc89904924ae56693fea1f36aa342263e7497195ac13a3ab870abd4a

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

require 'fanforce/api'

class Fanforce::PluginWorker::RunnerLocal
  include Fanforce::PluginWorker::Utils

  MAX_EXECUTION_TIME = 3300
  class Timeout < RuntimeError; end

  def initialize(worker_data, min_execution_time=300)
    raise "min_execution_time was set to #{min_execution_time}, which is #{min_execution_time - MAX_EXECUTION_TIME} seconds too long" if min_execution_time > MAX_EXECUTION_TIME
    log.debug '------------------------------------------------------------------------------------'
    log.debug 'LOADING WORKER ENV'
    ENV.each {|k,v| log.debug "#{k} = #{v}" }

    worker_data = worker_data.symbolize_keys
    @queue_id = worker_data[:queue_id] || (raise 'worker_data must contain queue_id')
    @current_params = MultiJson.load(worker_data[:params].to_json, symbolize_keys: true)
    @current_retries = 0
  end

  def run_job(&code_block)
    log.debug '------------------------------------------------------------------------------------'
    log.debug 'PROCESSING JOB...'
    log.debug '------------------------------------------------------------------------------------'

    response = code_block.call(@current_params.clone, retries: @current_retries, queue_id: @queue_id)

    log.debug 'WINDING DOWN WORKER!'
    response
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fanforce-plugin-worker-2.0.0.rc15 lib/fanforce/plugin_worker/runner_local.rb
fanforce-plugin-worker-2.0.0.rc14 lib/fanforce/plugin_worker/runner_local.rb
fanforce-plugin-worker-2.0.0.rc13 lib/fanforce/plugin_worker/runner_local.rb
fanforce-plugin-worker-2.0.0.rc12 lib/fanforce/plugin_worker/runner_local.rb
fanforce-plugin-worker-2.0.0.rc11 lib/fanforce/plugin_worker/runner_local.rb
fanforce-plugin-worker-2.0.0.rc10 lib/fanforce/plugin_worker/runner_local.rb