Skip to content

Instantly share code, notes, and snippets.

@therealjasonkenney
Created December 30, 2016 16:14
Show Gist options
  • Save therealjasonkenney/e919ca15611af2400e0570dab5217f20 to your computer and use it in GitHub Desktop.
Save therealjasonkenney/e919ca15611af2400e0570dab5217f20 to your computer and use it in GitHub Desktop.
module Etl
module CasUrl
class UnsuccessfulResponseError < ::StandardError; end
class Base
private_class_method :new
private
attr_reader :applicant_id, :cas_id, :response
def initialize(applicant_id, cas_id)
@applicant_id = applicant_id
@cas_id = cas_id
end
def response_dump
[response.body, response.code, response.message, response.headers.inspect].join("\n")
end
def request_etl
@response = self.class.post("#{applicant_id}/#{cas_id}")
raise UnsuccessfulResponseError, response_dump unless success?
end
def success?
response.body == 'SUCCESS'
end
end
end
end
Etl.configure do |c|
old_url = CasUrl::Factory.build(ENV.fetch('CAS3_0_ONE_BUTTON', 'default_url'))
new_url = CasUrl::Factory.build(ENV.fetch('CAS3_1_ONE_BUTTON', 'default_url'))
c.cas_url = {
1121: old_url,
1116: old_url,
1122: old_url,
1117: old_url,
1: old_url,
default: new_url
}
end
module Etl
module CasUrl
class Factory
private_class_method :new
def self.build(base_url)
Class.new(CasUrl::Base) do
include HTTParty
base_uri("#{base_url}/generateXMLAndPushToMQL2")
define_singleton_method :request_etl! do |applicant_id:, cas_id:|
new(applicant_id, cas_id).send(:request_etl)
end
end
end
end
end
module Etl
class RequeueApplicantJob
include Resque::Plugins::Status
def self.perform
at(1,2,'Requesting from CAS Server')
cas_url_for(cas_id).request_etl!(applicant_id: applicant_id, cas_id: cas_id)
at(2,2, 'Applicant is back on the queue.')
end
private
def applicant_id
options.fetch('applicant_id')
end
def cas_id
options.fetch('cas_id')
end
def cas_url_for(cas_id)
Etl.configuration.cas_url[cas_id.to_sym] || Etl.configuration.cas_url.fetch(:default)
end
end
end
@therealjasonkenney
Copy link
Author

So you just need to do:

# In config/environment.rb
Etl.configure do |c|
  old_url = CasUrl::Factory.build(ENV.fetch('CAS3_0_ONE_BUTTON', 'default_url'))
  new_url = CasUrl::Factory.build(ENV.fetch('CAS3_1_ONE_BUTTON', 'default_url'))
  
  c.cas_url = {
    1121: old_url,
    1116: old_url,
    1122: old_url,
    1117: old_url,
    1: old_url,
    default: new_url
  }
end
# In the Job instead of sleep (May need to add logic for gpa request, as in what to do with that :/)
RequeueApplicantJob.create(applicant_id: ..., cas_id: ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment