Skip to content
This repository was archived by the owner on Feb 20, 2022. It is now read-only.

Commit 93495ba

Browse files
committed
basic webhook on job complete
1 parent 8c0090f commit 93495ba

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

docker/app/jobs/runner_job.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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!

docker/app/models/job.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Generic Job
5+
#
16
class 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
1646
end

docker/config/webhooks.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
development:
2+
webhooks:
3+
runner_job: <%= ENV['JOB_WEBHOOK_URL'] %>
4+
production:
5+
webhooks:
6+
runner_job: <%= ENV['JOB_WEBHOOK_URL'] %>

0 commit comments

Comments
 (0)