Class: Izanami::Workers::Watchdog
- Inherits:
-
Object
- Object
- Izanami::Workers::Watchdog
- Defined in:
- lib/izanami/workers/watchdog.rb
Overview
Utility worker that watch the IZANAMI_SANDBOX repository and updates the content each IZANAMI_WATCHDOG_SLEEP_TIME time via git and bundler.
Instance Method Summary collapse
-
#call ⇒ Object
Main action.
-
#cmd ⇒ String
Shell commands to keep the repo updated.
-
#shell_options ⇒ Hash
Options for the new process.
-
#update_repo ⇒ Object
Update the repo.
-
#wait_time ⇒ Fixnum
Time to wait between each update.
Instance Method Details
#call ⇒ Object
Main action. Updates the repo in a loop, waiting the defined time.
15 16 17 18 19 20 |
# File 'lib/izanami/workers/watchdog.rb', line 15 def call loop do update_repo sleep wait_time end end |
#cmd ⇒ String
Shell commands to keep the repo updated.
50 51 52 53 54 55 |
# File 'lib/izanami/workers/watchdog.rb', line 50 def cmd [ 'git pull', 'bundle install', ].join('&&') end |
#shell_options ⇒ Hash
Options for the new process.
Here we define the directory for the cap process, which is the ENV configuration variable.
43 44 45 |
# File 'lib/izanami/workers/watchdog.rb', line 43 def { chdir: ENV['IZANAMI_SANDBOX'] } end |
#update_repo ⇒ Object
Update the repo. Prints to $stdout the results of the shell commands.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/izanami/workers/watchdog.rb', line 23 def update_repo Open3.popen2e(cmd, ) do |stdin, stdout, thread| while (line = stdout.gets) $stdout.puts line.chomp end status = thread.value.success? ? 'success' : 'fail' $stdout.puts "\"#{cmd}\" => #{status}" stdin.close stdout.close end end |
#wait_time ⇒ Fixnum
Time to wait between each update.
Can be configured with the ENV variable.
62 63 64 65 |
# File 'lib/izanami/workers/watchdog.rb', line 62 def wait_time time = ENV['IZANAMI_WATCHDOG_SLEEP_TIME'] || 300 time.to_i end |