patriot-workflow-scheduler 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2f52963b03deb11f61726fe49e77f6712b98dbe
4
- data.tar.gz: b05887e2a2fe307e8201d79e342547223dcafae1
3
+ metadata.gz: 171fc8719f6d43b4923df7c7f6441d9953aba4c9
4
+ data.tar.gz: 1c21f08807b6bf8b5ffee473184cbc972323d75e
5
5
  SHA512:
6
- metadata.gz: 9203fe98d1ab635950a4d8883be8af94e8ca33328acb12fbc4728898a0dfc074ccb5b9418c7f89331fe030a956f4dd10cf1d9c59d02c2869b516988f5de884f3
7
- data.tar.gz: 8e3b4677a6ba120cec68f445632a5534c63c64330da1d444bf0949ff5fa72dad601106f3cf8e446ee71a3a123e55c9a0b54d9e9cf5c9ad14eaed4b4284b3d0f8
6
+ metadata.gz: e6cf0a2084f683b914c01107e3884e61ad79ee0038f93dd5febe848e11a181d11692837e791ee5b441cd22fe98f4de6242db7379a29b753bca643f097e5221a1
7
+ data.tar.gz: f56e71de2572befe76194efe4a89e2f8874dcac4443ef12c5495ebbfef007a16df17710722e81b15bb2e688755b27f2a7709c3183c5143c56be92b79e5b73e1f
@@ -0,0 +1,66 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ module Patriot
5
+ module Command
6
+ module PostProcessor
7
+ class HttpNotification < Patriot::Command::PostProcessor::Base
8
+
9
+ CALLBACK_URL = :callback_url
10
+ ON_PROP_KEY = :on
11
+
12
+ declare_post_processor_name :http_notification
13
+
14
+ def validate_props(props)
15
+ raise "#{CALLBACK_URL} is not specified" unless props.has_key?(CALLBACK_URL)
16
+ raise "#{CALLBACK_URL} is not a correct URL" unless valid_url?(props.fetch(CALLBACK_URL, ""))
17
+ raise "#{ON_PROP_KEY} is not specified" unless props.has_key?(ON_PROP_KEY)
18
+ end
19
+
20
+ def process(cmd, worker, job_ticket)
21
+ on = @props[ON_PROP_KEY]
22
+ on = [on] unless on.is_a?(Array)
23
+ on = on.map{|o| Patriot::Command::ExitCode.value_of(o)}
24
+ exit_code = job_ticket.exit_code
25
+ return unless on.include?(exit_code)
26
+
27
+ callback_url = @props[CALLBACK_URL]
28
+ case exit_code
29
+ when Patriot::Command::ExitCode::SUCCEEDED then send_callback(job_ticket.job_id, callback_url, "SUCCEEDED")
30
+ when Patriot::Command::ExitCode::FAILED then send_callback(job_ticket.job_id, callback_url, "FAILED")
31
+ end
32
+ end
33
+
34
+ def send_callback(job_id, callback_url, state)
35
+ retries = 0
36
+ begin
37
+ return RestClient.post(
38
+ callback_url,
39
+ {'job_id' => job_id, 'state' => state }.to_json,
40
+ :content_type => 'application/json'
41
+ )
42
+ rescue RestClient::Exception => error
43
+ retries += 1
44
+ if retries < 3
45
+ retry
46
+ else
47
+ raise error
48
+ end
49
+ end
50
+ end
51
+
52
+ def valid_url?(url)
53
+ begin
54
+ URI.parse(url)
55
+ rescue URI::InvalidURIError
56
+ return false
57
+ end
58
+ return true
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+
@@ -9,6 +9,7 @@ module Patriot
9
9
  require 'patriot/command/post_processor/discard_on_fail'
10
10
  require 'patriot/command/post_processor/retrial'
11
11
  require 'patriot/command/post_processor/mail_notification'
12
+ require 'patriot/command/post_processor/http_notification'
12
13
  end
13
14
  end
14
15
  end
@@ -1,3 +1,3 @@
1
1
  module Patriot
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end