Skip to content

Instantly share code, notes, and snippets.

@geoffharcourt
Created September 15, 2015 18:18
Show Gist options
  • Save geoffharcourt/2559a681c1d9b47bab38 to your computer and use it in GitHub Desktop.
Save geoffharcourt/2559a681c1d9b47bab38 to your computer and use it in GitHub Desktop.
class CronutNotifier
def initialize(job_id)
@job_id = job_id
end
def notify
if ENV["CRONUT_SERVER_HOST"].present?
HTTParty.post(
ping_url,
headers: headers_hash,
query: { public_id: public_id }
)
end
rescue *HTTP_ERRORS
# noop
end
protected
attr_reader :job_id
private
def headers_hash
{
"User-Agent" => "Cortex-#{Rails.env}",
"X-CRONUT-API-TOKEN" => Rails.application.secrets.cronut_ping_api_token
}
end
def ping_url
"#{ENV["CRONUT_SERVER_HOST"]}/ping"
end
def public_id
"#{timestamp}-#{job_id}"
end
def timestamp
Time.now.to_i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment