Skip to content

Instantly share code, notes, and snippets.

@3dd13
Created November 27, 2012 08:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3dd13/4153156 to your computer and use it in GitHub Desktop.
Save 3dd13/4153156 to your computer and use it in GitHub Desktop.
Runing single ruby file on heroku
source 'https://rubygems.org'
#!/usr/bin/env ruby
require 'net/http'
require 'net/smtp'
MAILING_LIST = ['your_email@example.com', 'another_email@example.com']
def ping_api_1
post_check('http://example.com/resources')
end
def ping_api_2
get_check('http://example.com/resources')
end
def get_check(url)
begin
res = Net::HTTP.get_response(URI(url))
if res.code == "200"
puts "alive #{url}"
else
send_message("Something wrong with #{url}")
end
rescue => e
send_message("Something wrong with #{url} #{e.inspect}")
end
end
def post_check(url)
# post something ...
end
def full_message(msg)
<<MESSAGE_END
From: Bot Monitor <bot_email@gmail.com>
To: Developers
MIME-Version: 1.0
Content-type: text/html
Subject: #{msg}
<h2>Error</h2>
<br/>
#{msg}<br/>
<br/>
MESSAGE_END
end
def send_message(msg)
smtp = Net::SMTP.new 'smtp.gmail.com', 587
smtp.enable_starttls
smtp.start("gmail.com", "your_login@gmail.com", 'your_password', :login) do |smtp|
smtp.send_message(full_message(msg), "your_login@gmail.com", MAILING_LIST)
end
end
puts "Start scanning at #{Time.now}"
threads = []
threads << Thread.new { ping_api_1 }
threads << Thread.new { ping_api_2 }
threads.each do |t|
t.join
end
puts "Complete scanning at #{Time.now}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment