utilisation de la gem daemons

29 views
Skip to first unread message

ziburudebian

unread,
Aug 12, 2016, 7:02:02 PM8/12/16
to Railsfrance
bonjour à tous

j'execute la fonction runexecution depuis mon formulaire slim

class ExecutionsController < ApplicationController
require 'daemons'

def after_initialize()
@res_graph = ""
@res_exe = ""
end

def runexecution
# ============================================================================================================
# DESCRIPTION :
#
# ============================================================================================================
result_detection = ""
result_decision = ""
exedate = params[:exedate] + " " + params[:exeheure] #2016年08月05日 12:30"
frequence = params[:exefreq] # 15.00
listclientselectionne = params[:liste] #1-9-6-3
logger.info("******************loopstart")

pwd = File.dirname(File.expand_path(__FILE__))
file_to_run = pwd + "/execution_run.rb"
options = { :app_name => 'myapp',
:ARGV => ['start', '-f', '--', exedate, frequence, listclientselectionne]
}
logger.info("******************options="+options.to_s)
Daemons.run_proc(file_to_run, options) do
logger.info("******************daemon")
loop do
sleep(10)
end
end

# Rails.logger = ActiveSupport::BufferedLogger.new('./log')
renderexe(action,client,result_detection,result_decision)
end

def renderexe(action,client,result_detection,result_decision)
@res_exe = action.to_s + '$' + client.to_s + '$' + result_detection + '$' + result_decision
respond_to do |format|
format.html {redirect_to "resultat_"+client.to_s}
format.js {}
format.json {render :json => @res_exe.to_json}
end
end
end # class

ensuite voici le code du script execution_run.rb:

#!/usr/bin/env /home/hodei/prosafe/script/rails runner
require File.expand_path('../../../config/environment', __FILE__)

# argv_o = date+heure
# argv_1 = frequence
# argv_2 = clients

exedate = ARGV[0]
frequence = ARGV[1]
listclientselectionne = ARGV[2] #2-9-6
Rails.logger.info("******************param=" + exedate.to_s + " " + frequence.to_s + " " + listclientselectionne.to_s)
# ensuite le programme fait des actions de mise à jour en bd que j'ai pour l'instant commenté

Mais le ptrogramme s'arrete et fait une fatal error : il ne semble pas exécuté le script execution_run.rb

Voici la log :

I, [2016年08月12日T11:45:38.686232 #3122] INFO -- : ******************param=-e production -d
I, [2016年08月12日T11:45:48.458130 #3129] INFO -- : Started GET "/executions/execution" for 192.168.150.254 at 2016年08月12日 11:45:48 +0200
I, [2016年08月12日T11:45:48.520234 #3129] INFO -- : Processing by ExecutionsController#execution as HTML
I, [2016年08月12日T11:45:48.724800 #3129] INFO -- : Rendered executions/execution.html.slim within layouts/application (175.1ms)
I, [2016年08月12日T11:45:48.735202 #3129] INFO -- : Rendered tpl/_header.html.slim (9.0ms)
I, [2016年08月12日T11:45:48.782857 #3129] INFO -- : Rendered tpl/_menu.html.slim (47.2ms)
I, [2016年08月12日T11:45:48.797932 #3129] INFO -- : Rendered tpl/_footer.html.slim (14.6ms)
I, [2016年08月12日T11:45:48.798224 #3129] INFO -- : Completed 200 OK in 278ms (Views: 227.2ms | ActiveRecord: 26.9ms)
I, [2016年08月12日T11:45:52.315302 #3129] INFO -- : Started POST "/runexecution" for 192.168.150.254 at 2016年08月12日 11:45:52 +0200
I, [2016年08月12日T11:45:52.316477 #3129] INFO -- : Processing by ExecutionsController#runexecution as JS
I, [2016年08月12日T11:45:52.316533 #3129] INFO -- : Parameters: {"utf8"=>"âœ"", "idpatient_1"=>"", "idpatient_2"=>"", "exedate"=>"2015年10月03日", "exeheure"=>"08:30", "exefreq"=>"0.05", "clientenabled_1"=>"Activer"}
I, [2016年08月12日T11:45:52.418192 #3129] INFO -- : ******************listclientselectionne=
I, [2016年08月12日T11:45:52.418257 #3129] INFO -- : ******************action=clientenabled
I, [2016年08月12日T11:45:52.421034 #3129] INFO -- : Rendered executions/runexecution.js.erb (0.4ms)
I, [2016年08月12日T11:45:52.421243 #3129] INFO -- : Completed 200 OK in 105ms (Views: 2.7ms | ActiveRecord: 14.7ms)
I, [2016年08月12日T11:45:54.244868 #3129] INFO -- : Started POST "/runexecution" for 192.168.150.254 at 2016年08月12日 11:45:54 +0200
I, [2016年08月12日T11:45:54.245899 #3129] INFO -- : Processing by ExecutionsController#runexecution as JS
I, [2016年08月12日T11:45:54.245953 #3129] INFO -- : Parameters: {"utf8"=>"âœ"", "idpatient_1"=>"1", "idpatient_2"=>"", "exedate"=>"2015年10月03日", "exeheure"=>"08:30", "exefreq"=>"0.05", "loopstart"=>"Démarrer"}
I, [2016年08月12日T11:45:54.257036 #3129] INFO -- : ******************listclientselectionne=1
I, [2016年08月12日T11:45:54.257078 #3129] INFO -- : ******************action=loopstart
I, [2016年08月12日T11:45:54.257118 #3129] INFO -- : ******************loopstart
I, [2016年08月12日T11:45:54.257173 #3129] INFO -- : ******************options={:app_name=>"myapp", :ARGV=>["start", "-f", "--", "2015年10月03日 08:30", "0.05", "1"]}
I, [2016年08月12日T11:45:54.266662 #3132] INFO -- : Completed 500 Internal Server Error in 21ms
F, [2016年08月12日T11:45:54.270756 #3132] FATAL -- : 
SystemExit (exit):
 app/controllers/executions_controller.rb:29:in `runexecution'

la ligne 29 c'est
Daemons.run_proc(file_to_run, options)

Merci pour votre aide

Reply all
Reply to author
Forward
0 new messages