Class: Sklaventreiber::HerokuConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/sklaventreiber/herokuconnection.rb

Constant Summary collapse

@@api =
nil
@@worker =
0

Class Method Summary collapse

Class Method Details

.fire_workerObject



45
46
47
48
49
50
51
# File 'lib/sklaventreiber/herokuconnection.rb', line 45

def self.fire_worker
	@@worker = 0
	@@api.post_ps_scale( Sklaventreiber::Config::HEROKU_APP, "worker", @@worker.to_s )
	if Sklaventreiber::Config::SKLAVENTREIBER_LOG
		puts "Sklaventreiber fired the worker."
	end
end

.hire_workerObject



37
38
39
40
41
42
43
# File 'lib/sklaventreiber/herokuconnection.rb', line 37

def self.hire_worker
	@@worker = 1
	@@api.post_ps_scale( Sklaventreiber::Config::HEROKU_APP, "worker",  @@worker.to_s )
	if Sklaventreiber::Config::SKLAVENTREIBER_LOG
		puts "Sklaventreiber hired a worker."
	end
end

.initObject

singleton for api connection



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sklaventreiber/herokuconnection.rb', line 10

def self.init
	# if there is no api connection yet
	if @@api == nil
		# then init api connection
		if Sklaventreiber::Config::HEROKU_API_KEY != nil
			@@api = Heroku::API.new( :api_key => Sklaventreiber::Config::HEROKU_API_KEY, :mock => Sklaventreiber::Config::SKLAVENTREIBER_MOCK )
		else
			@@api = Heroku::API.new( :username => Sklaventreiber::Config::HEROKU_USERNAME, :password => Sklaventreiber::Config::HEROKU_PASSWORD, :mock => Sklaventreiber::Config::SKLAVENTREIBER_MOCK )
		end

		# then init worker count
		@@worker = 0
		response = @@api.get_ps( Sklaventreiber::Config::HEROKU_APP )
		if ( response.status == 200 )
			processes = response.body
			processes.each do |proc|
				if ( proc["process"].start_with?( "worker") )
					@@worker = @@worker + 1
				end
			end
		end
		if Sklaventreiber::Config::SKLAVENTREIBER_LOG
			puts "Sklaventreiber: Worker count at start = " + @@worker.to_s
		end
	end		
end

.is_fired?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/sklaventreiber/herokuconnection.rb', line 53

def self.is_fired?
	return @@worker == 0
end

.is_hired?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/sklaventreiber/herokuconnection.rb', line 57

def self.is_hired?
	return @@worker == 1
end