I have a sinatra app that executes cucumber tests and sends email notification with their results. Email gem is Pony, and there is a haml template for this notification.
This logic works within a route:
require 'sinatra'
require 'haml'
require 'pony'
get "/execute_all/?" do
execute_all_tests()
Pony.mail :to => "recipients@email.com",
:from => "do-not-reply@email.com",
:subject => "Test results,
:html_body => haml(:email_layout)
redirect "/"
end
However when I use scheduled job with rufus scheduler for these actions, I get following exception:
scheduler caught exception:
undefined method `haml' for main:Object
Code is copypasta from route:
scheduler = Rufus::Scheduler.start_new
scheduler.every '2h' do
execute_all_tests()
Pony.mail :to => "recipients@email.com",
:from => "do-not-reply@email.com",
:subject => "Test results,
:html_body => haml(:email_layout)
end
All two methods are in the same file, that is executed to run Sinatra app.
How to get rid of this exception, and send emails with haml template as scheduled job?