Skip to content

Commit

Permalink
Move global variable definition to settings file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Zoldak committed Mar 2, 2014
1 parent 777c83c commit 4d058a9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 39 deletions.
6 changes: 6 additions & 0 deletions config/settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
JENKINS_BASE_URL = 'https://jenkins.testeng.edx.org'
JENKINS_JOB_NAME = 'edx-all-tests-auto-master'
JENKINS_JOB_URL = JENKINS_BASE_URL + '/job/' + JENKINS_JOB_NAME

MATHWORKS_ENABLED = false
MATHWORKS_API_KEY = 'API_KEY_HERE'
4 changes: 0 additions & 4 deletions jobs/edx-violations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
require "openssl"
require "nokogiri"

JENKINS_BASE_URL = 'https://jenkins.testeng.edx.org'
JENKINS_JOB_NAME = 'edx-all-tests-auto-master'
JENKINS_JOB_URL = JENKINS_BASE_URL + '/job/' + JENKINS_JOB_NAME

SCHEDULER.every '1m', :first_in => 0 do |job|

violations_uri = JENKINS_JOB_URL + '/SHARD=1,TEST_SUITE=quality/violations/?'
Expand Down
3 changes: 0 additions & 3 deletions jobs/edx_jenkins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
require 'openssl'
require 'json'

JENKINS_JOB_NAME = 'edx-all-tests-auto-master'
JENKINS_JOB_URL = JENKINS_BASE_URL + '/job/' + JENKINS_JOB_NAME

current_status = nil
SCHEDULER.every '10s', :first_in => 0 do
last_status = current_status
Expand Down
4 changes: 0 additions & 4 deletions jobs/js_coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
require 'openssl'
require 'json'

JENKINS_BASE_URL = 'https://jenkins.testeng.edx.org'
JENKINS_JOB_NAME = 'edx-all-tests-auto-master'
JENKINS_JOB_URL = JENKINS_BASE_URL + '/job/' + JENKINS_JOB_NAME

# :first_in sets how long it takes before the job is first run. In this case, it is run immediately
SCHEDULER.every '5m', :first_in => 0 do |job|

Expand Down
53 changes: 29 additions & 24 deletions jobs/mathworks-status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,40 @@
require "uri"

uri = URI.parse("https://prod.mss-mathworks.com/stateless/mooc/edX")
data = {"xqueue_body" => "{\"student_response\": \"x=1\\n\", \"grader_payload\": \"%api_key=API_KEY_HERE\\n%%\\nassert(isequal(x,1))\\n\"}"}.to_json
api_key = MATHWORKS_API_KEY
data = {"xqueue_body" => "{\"student_response\": \"x=1\\n\", \"grader_payload\": \"%api_key=#{api_key}\\n%%\\nassert(isequal(x,1))\\n\"}"}.to_json

# :first_in sets how long it takes before the job is first run. In this case, it is run immediately
# TODO: rescue Timeout::Error if the back end does not respond
SCHEDULER.every '1m', :first_in => 0 do |job|
if MATHWORKS_ENABLED
# TODO: rescue Timeout::Error if the back end does not respond
SCHEDULER.every '1m', :first_in => 0 do |job|

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri)
request.body = data
request["Content-Type"] = "application/json"
response = http.request(request)
b = response.body
fault = JSON.parse(b)['fault']
correct = JSON.parse(b)['correct']
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri)
request.body = data
request["Content-Type"] = "application/json"
response = http.request(request)
b = response.body
fault = JSON.parse(b)['fault']
correct = JSON.parse(b)['correct']

# note: status warning=red and danger=orange
if response.code == '200'
if fault.nil?
if correct == true
send_event('mathworks_status', { title: 'Mathworks API', text: "Up", status: 'ok' })
else # responsed but with the wrong value for "correct"
send_event('mathworks_status', { title: 'Mathworks API: Error', text: b, status: 'danger' })
# note: status warning=red and danger=orange
if response.code == '200'
if fault.nil?
if correct == true
send_event('mathworks_status', { title: 'Mathworks API', text: "Up", status: 'ok' })
else # responsed but with the wrong value for "correct"
send_event('mathworks_status', { title: 'Mathworks API: Error', text: b, status: 'danger' })
end
else
send_event('mathworks_status', { title: 'Mathworks API', text: fault, status: 'warning' })
end
else
send_event('mathworks_status', { title: 'Mathworks API', text: fault, status: 'warning' })
send_event('mathworks_status', { title: 'Mathworks API', text: response.code, status: 'danger' })
end
else
send_event('mathworks_status', { title: 'Mathworks API', text: response.code, status: 'danger' })
end
else
send_event('mathworks_status', { title: 'Mathworks API', text: "Not monitoring", status: 'ok' })
end

4 changes: 0 additions & 4 deletions jobs/python_coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
require "nokogiri"


JENKINS_BASE_URL = 'https://jenkins.testeng.edx.org'
JENKINS_JOB_NAME = 'edx-all-tests-auto-master'
JENKINS_JOB_URL = JENKINS_BASE_URL + '/job/' + JENKINS_JOB_NAME

# :first_in sets how long it takes before the job is first run. In this case, it is run immediately
SCHEDULER.every '5m', :first_in => 0 do |job|

Expand Down

0 comments on commit 4d058a9

Please sign in to comment.