Sha256: b081df5b023339e9727939b1c0adbe94743cf89e423a064db17618abc25a12fa

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 KB

Contents

$pid_file = "/tmp/matias.pid"

God.task do |w|
  w.name = "watcher"
  w.interval = 5.seconds
  w.valid_states = [:init, :up, :down]
  w.initial_state = :init

  # determine the state on startup
  w.transition(:init, { true => :up, false => :down }) do |on|
    on.condition(:process_running) do |c|
      c.running = true
      c.pid_file = $pid_file
    end
  end

  # when process is up
  w.transition(:up, :down) do |on|
    # transition to 'start' if process goes down
    on.condition(:process_running) do |c|
      c.running = false
      c.pid_file = $pid_file
    end

    # send up info
    on.condition(:lambda) do |c|
      c.lambda = lambda do
        puts 'yay I am up'
        false
      end
    end
  end

  # when process is down
  w.transition(:down, :up) do |on|
    # transition to 'up' if process comes up
    on.condition(:process_running) do |c|
      c.running = true
      c.pid_file = $pid_file
    end

    # send down info
    on.condition(:lambda) do |c|
      c.lambda = lambda do
        puts 'boo I am down'
        false
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
resurrected_god-0.14.0 test/configs/matias/matias.god
mcproc-2016.2.20 test/configs/matias/matias.god
god-0.13.7 test/configs/matias/matias.god
god-0.13.6 test/configs/matias/matias.god
god-0.13.5 test/configs/matias/matias.god
god-0.13.4 test/configs/matias/matias.god
god-0.13.3 test/configs/matias/matias.god
god-0.13.2 test/configs/matias/matias.god
god-0.13.1 test/configs/matias/matias.god
god-0.13.0 test/configs/matias/matias.god
god-0.12.1 test/configs/matias/matias.god
god-0.12.0 test/configs/matias/matias.god