Skip to content
Browse files

restructured

  • Loading branch information...
1 parent 36477ba commit ea79ae41cd8639684e7bf93baf5c121c8263d21a @hsbt committed Mar 5, 2012
View
8 lib/heroku_scale_scheduler.rb
@@ -1,5 +1,3 @@
-module HerokuScaleScheduler
- class Railtie < Rails::Railtie
- rake_tasks { load 'heroku_scale_scheduler/tasks/heroku_scale_scheduler.rake' }
- end
-end
+require 'heroku_scale_scheduler/config'
+require 'heroku_scale_scheduler/client'
+require 'heroku_scale_scheduler/railtie'
View
22 lib/heroku_scale_scheduler/client.rb
@@ -0,0 +1,22 @@
+require 'heroku/client'
+
+module HerokuScaleScheduler
+ class Client
+ def initialize(type)
+ @type = type
+ end
+
+ def run
+ client = Heroku::Client.new(*Heroku::Auth.read_credentials)
+ config = HerokuScaleScheduler::Config.read_config
+ run_at = (Time.now.strftime('%H%M').to_i / 10) * 10
+
+ if qty = config[@type.to_s][run_at]
+ case @type
+ when :dynos then client.set_dynos(config['app'], qty)
+ when :workers then client.set_workers(config['app'], qty)
+ end
+ end
+ end
+ end
+end
View
11 lib/heroku_scale_scheduler/config.rb
@@ -0,0 +1,11 @@
+module HerokuScaleScheduler
+ class Config
+ def self.read_config
+ if File.exists? Rails.root.join('config', 'heroku_ps.yml')
+ YAML.load(Rails.root.join('config', 'heroku_ps.yml'))
+ else
+ {}
+ end
+ end
+ end
+end
View
5 lib/heroku_scale_scheduler/railtie.rb
@@ -0,0 +1,5 @@
+module HerokuScaleScheduler
+ class Railtie < Rails::Railtie
+ rake_tasks { load 'heroku_scale_scheduler/tasks/heroku_scale_scheduler.rake' }
+ end
+end
View
15 lib/heroku_scale_scheduler/tasks/heroku_scale_scheduler.rake
@@ -1,24 +1,13 @@
-require 'heroku/client'
-
-client = Heroku::Client.new(*Heroku::Auth.read_credentials)
-config = if File.exists? Rails.root.join('config', 'heroku_ps.yml')
- YAML.load(Rails.root.join('config', 'heroku_ps.yml'))
- else
- {}
- end
-
namespace :heroku do
namespace :scale do
desc 'scaling heroku dynos'
task :dynos do
- qty = config['dynos'][Time.now.strftime('%H%M')]
- client.set_dynos(config['app'], qty) if qty
+ HerokuScaleScheduler::Client.new(:dynos).run
end
desc 'scaling heroku workers'
task :workers do
- qty = config['workers'][Time.now.strftime('%H%M')]
- client.set_workers(config['app'], qty) if qty
+ HerokuScaleScheduler::Client.new(:workers).run
end
end
end

0 comments on commit ea79ae4

Please sign in to comment.
Something went wrong with that request. Please try again.