Module: Sklaventreiber::WorkerPlugin::InstanceMethods

Defined in:
lib/sklaventreiber/workerplugin.rb

Instance Method Summary collapse

Instance Method Details

#after_destroyObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sklaventreiber/workerplugin.rb', line 24

def after_destroy
	super
	if Sklaventreiber::Config::SKLAVENTREIBER_LOG
		puts "Sklaventreiber: Job #{self.id} destroyed."
	end
	Sklaventreiber::HerokuConnection.init()
	# if there are no more jobs to work on
	if ( Navvy::Job.filter( :failed_at => nil, :completed_at => nil ).count == 0 )
		# then fire worker
		Sklaventreiber::HerokuConnection.fire_worker()
	end
end

#after_updateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sklaventreiber/workerplugin.rb', line 37

def after_update
	super

	if Sklaventreiber::Config::SKLAVENTREIBER_LOG
		puts "Sklaventreiber: Job #{self.id} updated."
	end
	Sklaventreiber::HerokuConnection.init()

	# check if failed
	if ( self.failed? == true )
		# check if there are uncompleted jobs left
		if ( Job.filter( :failed_at => nil, :completed_at => nil ).count == 0 )
			# then fire worker
			Sklaventreiber::HerokuConnection.fire_worker()
		end
	end
end

#before_createObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sklaventreiber/workerplugin.rb', line 11

def before_create
				if Sklaventreiber::Config::SKLAVENTREIBER_LOG
		puts "Sklaventreiber: Job created."
	end
	Sklaventreiber::HerokuConnection.init()
	# if there is no worker hired
	if ( Sklaventreiber::HerokuConnection.is_fired?() )
		# then hire one
		Sklaventreiber::HerokuConnection.hire_worker()
	end
	super
end