diff options
author | mguetlein <martin.guetlein@gmail.com> | 2012-07-09 15:05:13 +0200 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2012-07-09 15:05:13 +0200 |
commit | d8f8050ba8bf47c5a272bcb937b4ee4f18ac5da0 (patch) | |
tree | 86a0c725805e200aa1008ecaf63a4ce10143360f | |
parent | b75e7f9536df1b0b2da3186b8150668263e1539a (diff) |
add a pid check for local-running task
-rw-r--r-- | lib/task.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/task.rb b/lib/task.rb index c73793a..b56d477 100644 --- a/lib/task.rb +++ b/lib/task.rb @@ -72,7 +72,7 @@ module OpenTox end end task.pid = task_pid - #LOGGER.debug "Started task: "+task.uri.to_s + #LOGGER.debug "Started task: "+task.uri.to_s+" "+task_pid.to_s task end @@ -239,6 +239,15 @@ module OpenTox end =end + private + def pid_found? + if metadata["PID"] + process = `ps -ef | grep #{metadata["PID"]}` + return process.chomp.size>0 && process=~/ruby/ + end + end + + public # waits for a task, unless time exceeds or state is no longer running # @param [optional,OpenTox::Task] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly # @param [optional,Numeric] dur seconds pausing before cheking again for completion @@ -251,6 +260,7 @@ module OpenTox LOGGER.debug "start waiting for task "+@uri.to_s.chomp+" at: "+Time.new.to_s+", waiting at least until "+due_to_time.to_s load_metadata # for extremely fast tasks + pid_found_on_start = pid_found? check_state while self.running? or self.queued? sleep dur @@ -263,6 +273,12 @@ module OpenTox if (Time.new > due_to_time) raise "max wait time exceeded ("+DEFAULT_TASK_MAX_DURATION.to_s+"sec), task: '"+@uri.to_s+"'" end + if pid_found_on_start and !(pid_found?) # the pid was found on startup, but not anymore + sleep 3 #make sure it has not just stopped and the task is not updated yet + load_metadata + check_state + raise "task process with PID #{metadata["PID"]} is not running any longer" if self.running? or self.queued? + end end waiting_task.waiting_for(nil) if waiting_task LOGGER.debug "Task '"+@metadata[OT.hasStatus].to_s+"': "+@uri.to_s.chomp+", Result: #{@metadata[OT.resultURI].to_s.gsub("\n"," \\n ")}" |