Dans mes apps/contrôleurs/model_controller.rb Je (nom des modèles/méthodes ont été changés pour protéger les innocents):Workling magasin de retour valeur ne récupérer de définir
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
Dans app/travailleurs/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
Notez que l'ensemble et obtenir fonctionnent correctement ici dans ce travailleur. Le problème est plus tard ...
Retour à app/views/modèle/index.html.rb, j'ai un sondage d'aide prototype d'une demande au même contrôleur pour déterminer si le travail de fond est terminée:
<%= periodically_call_remote(:url => { :action => :background_complete }, :frequency => 5, :update => 'status_div') %>
Et dans les applications/contrôleurs/model_controller.rb, la fonction de contrôle de l'état de la tâche de fond:
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;'>"[email protected]+"</span>"
else
@result = "none" if @result.nil?
render :text => "<span style='font-size:12px;margin-left:20px;'>"[email protected]+"</span>"
end
end
end
end
Et enfin, dans config/environnements/development.rb:
Workling::Return::Store.instance = Workling::Return::Store::MemoryReturnStore.new
Workling::Remote.dispatcher = Workling::Remote::Runners::StarlingRunner.new
(Notez que j'ai essayé d'exécuter ceci avec et sans la dernière ligne commentée. Si elle est commentée, Workling revient à Spawn plutôt que Starling)
Le problème est que je reçois nul de cette ligne dans background_complete.
@result = Workling::Return::Store.get(task.process_id) #=> nil