Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add daemon_spawn #2

Merged
merged 1 commit into from
Feb 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rpi/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.bundle
.env
.env
tmp/
log/

2 changes: 2 additions & 0 deletions rpi/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ gem 'aws-sdk'
gem 'whenever'
gem 'rake'
gem 'iremocon'
gem 'daemon-spawn'

2 changes: 2 additions & 0 deletions rpi/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ GEM
uuidtools (~> 2.1)
chronic (0.10.2)
coderay (1.1.0)
daemon-spawn (0.4.2)
dotenv (0.9.0)
extlib (0.9.16)
faraday (0.9.0)
Expand Down Expand Up @@ -74,6 +75,7 @@ PLATFORMS
DEPENDENCIES
activesupport
aws-sdk
daemon-spawn
dotenv
google-api-client
iremocon
Expand Down
6 changes: 0 additions & 6 deletions rpi/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,3 @@ namespace :calendar do
end
end

namespace :manager do
desc 'start manager'
task :start do
ElectronicsManager.new.start
end
end
22 changes: 17 additions & 5 deletions rpi/electronics_manager.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
require 'yaml'
require 'iremocon'
require 'daemon_spawn'
require 'aws-sdk'
require 'dotenv'; Dotenv.load!
require 'active_support/all'

class ElectronicsManager
def initialize
class ElectronicsManager < DaemonSpawn::Base
def start(args)
@settings = YAML.load_file('settings.yml')
@iremocon = Iremocon.new(@settings['iremocon']['address'])
end

def start
puts 'start manager'
Process.daemon
loop do
queue.poll(idle_timeout: 60) do |message|
ray_number = commands[message.body]
Expand All @@ -24,6 +25,9 @@ def start
end
end

def stop
end

private

def commands
Expand All @@ -38,3 +42,11 @@ def queue
).queues[ENV['SQS_URL']]
end
end

ElectronicsManager.spawn!({
working_dir: __dir__,
pid_file: File.expand_path(__dir__ + '/tmp/manager.pid'),
log_file: File.expand_path(__dir__ + '/log/manager.log'),
sync_log: true,
singleton: true
})
Empty file added rpi/log/.gitkeep
Empty file.
Empty file added rpi/tmp/.gitkeep
Empty file.