This repository was archived by the owner on Feb 20, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ def perform
8181 puts "Processing results finished - #{ guid } "
8282
8383 job . complete!
84+ job . send_webhook
8485 puts "Runner job finished - #{ guid } "
8586 rescue StandardError => e
8687 job . failed!
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ #
4+ # Generic Job
5+ #
16class Job < ApplicationRecord
27 has_many :results
38
@@ -13,4 +18,29 @@ class Job < ApplicationRecord
1318 parse : 3 ,
1419 cleanup : 4
1520 } , _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
1646end
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