Class: QuartzPlugin

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/quartz_plugin.rb

Constant Summary collapse

@@version_major =
0
@@version_minor =
0
@@version_revision =
0

Instance Method Summary collapse

Constructor Details

#initialize(log, options) ⇒ QuartzPlugin

Returns a new instance of QuartzPlugin.



6
7
8
9
# File 'lib/plugins/quartz_plugin.rb', line 6

def initialize(log, options)
	@log = log
	@options = options
end

Instance Method Details

#get_versionObject



47
48
49
# File 'lib/plugins/quartz_plugin.rb', line 47

def get_version
	"#{@@version_major}.#{@@version_minor}.#{@@version_revision}"
end

#payload(message) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/plugins/quartz_plugin.rb', line 18

def payload(message)
	raw_payload = message['payload']
	@log.debug "Payload #{raw_payload}"
	parsed_payload = JSON.parse(raw_payload) unless raw_payload.nil?
	@log.debug "Parsed payload #{parsed_payload}"

	v = parsed_payload
	v = v.merge({'job_name' => message['job_name']})

	@log.debug "Payload #{v}"

	v
end

#run_result(success, message) ⇒ Object



11
12
13
14
15
16
# File 'lib/plugins/quartz_plugin.rb', line 11

def run_result(success, message)
	result = { :ok => success, :message => message }
	@log.debug "Job finished with result #{result}"

	result
end

#run_shell(command) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/plugins/quartz_plugin.rb', line 32

def run_shell(command)
	pid, stdin, stdout, stderr = Open4::popen4("#{command}")
	ignored, status = Process::waitpid2 pid

	if status.exitstatus == 0
		{ :ok => true, :message => stdout.read.strip }
	else
		{ :ok => false, :message => stderr.read.strip}
	end
end