I'm new to writing Rails rake tasks. I want to write a rake task that looks for calls that are within 30.minutes of being due and executing a mailer. Below is the code I would use out of the controller, how can I adapt this to my rake task?
@call = Call.find(params[:id])
if Time.zone.now < @call.transfer_date + 30.minutes
@call.units.each do |unit|
CallMailer.cancel_call(unit.incharge, @call).deliver
CallMailer.cancel_call(unit.attendant, @call).deliver
end
end
Any help is appreciated.