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, &code_block) 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 run_job(&code_block) end def run_job(&code_block) log.debug '------------------------------------------------------------------------------------' log.debug 'PROCESSING JOB...' log.debug '------------------------------------------------------------------------------------' code_block.call(@current_params.clone, retries: @current_retries, queue_id: @queue_id) log.debug 'WINDING DOWN WORKER!' end end