This repository was archived by the owner on Feb 20, 2022. It is now read-only.
File tree 3 files changed +37
-0
lines changed
3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ def perform
81
81
puts "Processing results finished - #{ guid } "
82
82
83
83
job . complete!
84
+ job . send_webhook
84
85
puts "Runner job finished - #{ guid } "
85
86
rescue StandardError => e
86
87
job . failed!
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Generic Job
5
+ #
1
6
class Job < ApplicationRecord
2
7
has_many :results
3
8
@@ -13,4 +18,29 @@ class Job < ApplicationRecord
13
18
parse : 3 ,
14
19
cleanup : 4
15
20
} , _prefix : :job
21
+
22
+ #
23
+ # Send an external webhook
24
+ #
25
+ def send_webhook
26
+ config = Rails . application . config_for ( :webhooks )
27
+
28
+ return unless config . webhooks
29
+
30
+ config . webhooks . each do |_k , webhook |
31
+ next if webhook . nil?
32
+
33
+ url = URI ( webhook )
34
+ headers = { 'content-type' => 'application/json' }
35
+ payload = {
36
+ 'job_id' => id ,
37
+ 'job_type' => kind ,
38
+ 'status' => status ,
39
+ 'results' => results . count
40
+ } . to_json
41
+ res = Net ::HTTP . post ( URI ( url ) , payload , headers )
42
+
43
+ res . code
44
+ end
45
+ end
16
46
end
Original file line number Diff line number Diff line change
1
+ development :
2
+ webhooks :
3
+ runner_job : <%= ENV['JOB_WEBHOOK_URL'] %>
4
+ production :
5
+ webhooks :
6
+ runner_job : <%= ENV['JOB_WEBHOOK_URL'] %>
You can’t perform that action at this time.
0 commit comments