lib/serfx/utils/async_job.rb
# start a background daemon and spawn another process to run specified
# command. writes back state information in the state file
# after spawning daemon process (state=invoking), after spawning the
# child process (state=running) and after reaping the child process
# (sate=finished).
#
# @return [String] 'success' if task is started
start a background daemon and spawn another process to run specified
command. writes back state information in the state file
after spawning daemon process (state=invoking), after spawning the
child process (state=running) and after reaping the child process
(sate=finished).
start a background daemon and spawn another process to run specified command . writes back state information in the state file after spawning daemon process ( state = invoking ) after spawning the child process ( state = running ) and after reaping the child process ( sate = finished ) .
def start
        if exists? || command.nil?
          return 'failed'
        end
        pid = fork do
          Process.daemon
          state = {
            ppid: Process.pid,
            status: 'invoking',
            pid: -1,
            time: Time.now.to_i
          }
          write_state(state)
          begin
            child_pid = Process.spawn(
              environment,
              command,
              out: stdout_file,
              err: stderr_file,
              chdir: cwd
            )
            state[:pid] = child_pid
            state[:status] = 'running'
            write_state(state)
            _, status = Process.wait2(child_pid)
            state[:exitstatus] = status.exitstatus
            state[:status] = 'finished'
          rescue Errno::ENOENT => e
            state[:error] = e.class.name
            state[:status] = 'failed'
          end
          write_state(state)
          exit 0
        end
        Process.detach(pid)
        'success'
      end
def start if exists? || command . nil? return 'failed' end pid = fork do Process . daemon state = { ppid : Process . pid , status : 'invoking' , pid : - 1 , time : Time . now . to_i } write_state ( state ) begin child_pid = Process . spawn ( environment , command , out : stdout_file , err : stderr_file , chdir : cwd ) state [ :pid ] = child_pid state [ :status ] = 'running' write_state ( state ) _ , status = Process . wait2 ( child_pid ) state [ :exitstatus ] = status . exitstatus state [ :status ] = 'finished' rescue Errno :: ENOENT => e state [ :error ] = e . class . name state [ :status ] = 'failed' end write_state ( state ) exit 0 end Process . detach ( pid ) 'success' end
start a background daemon and spawn another process to run specified
command.
start a background daemon and spawn another process to run specified command .
'success' if task is started
' success ' if task is started
String