In my apps/controllers/model_controller.rb I have (names of models/methods changed to protect the innocent):
def background_sync
@background_task_uid = Model.async_process_model_cache({:name => 'name'})
@model_sync = ModelSync.new # Adds a new record in the queue of pending jobs
@model_sync.process_id = @background_task_uid # Puts the background process id into the new ModelSync record
@model_sync.save
end
In app/workers/model_worker.rb:
def process_model_cache(options={})
[long background task]
result = Workling::Return::Store.set(options[:uid], 'done')
result = Workling::Return::Store.get(options[:uid]) #=> 'done'
end
Notice that the set and get are functioning properly here within this worker. The problem is later on...
Back in app/views/model/index.html.rb, I have a prototype helper polling a request to the same controller to determine whether the background job is complete:
<%= periodically_call_remote( :url => { :action => :background_complete }, :frequency => 5, :update => 'status_div') %>
And in apps/controllers/model_controller.rb, the function for checking the status of the background job:
def background_complete
@background_task_uid = ModelSync.find(:last)
if @background_task_uid
@background_task_uid.each do |task|
unless task.process_id == "" || task.process_id.nil?
@result = Workling::Return::Store.get(task.process_id) #=> nil
if @result.nil?
task.destroy
end
else
task.destroy
end
unless @result.nil?
render :text => "<span style='font-size:12px;margin-left:20px;'>"+@result+"</span>"
else
@result = "none" if @result.nil?
render :text => "<span style='font-size:12px;margin-left:20px;'>"+@result+"</span>"
end
end
end
end
And finally, in config/environments/development.rb:
Workling::Return::Store.instance = Workling::Return::Store::MemoryReturnStore.new
Workling::Remote.dispatcher = Workling::Remote::Runners::StarlingRunner.new
(Note that I've tried running this with and without the last line commented. If commented out, Workling reverts to Spawn rather than Starling.)
So the problem is that I get nil from this line in background_complete:
@result = Workling::Return::Store.get(task.process_id) #=> nil