- Read Tutorial
- Watch Guide Video
In this video, we are going to build a scheduling component that'll send our text messages and emails.
Go to your terminal and type the command,
heroku addons:create scheduler:standard
This will install the scheduler add-on for us.
Now, go to "https://dashboard.heroku.com/apps" because I think the easiest way to create a scheduler is to just set it up on heroku itself.
Select the app on your dashboard, and you'll see that it has added the Heroku Scheduler. Click on the scheduler, and it'll take you to a new window. Click on "Add a new job" button.
Now, type bundle exec rake notification:manager_email
. Before that, let's update the email address of the admin to a valid email ID.
Go back to the scheduler and change the frequency to daily as we want the system to send an email everyday to admin users. Also, convert the time to UTC. My client is in Texas, so they follow Central Time. I'm going to schedule it to run at 4:00pm Central Time, which converts to 21:00 hours in UTC. Finally, save it.
Likewise, add another job for text messages. The command for creating it is bundle exec rake notification:sms
. I'm going to set the frequency to daily for now because the scheduler does not have a weekly option. I'll check with the client on this. Set the time to 21:30pm as we don't want both the tasks to run at the same time.
Before you save, make sure the regular user has a valid phone number to receive text messages.
Or, you know what. Let's build the weekly scheduler as it's not so tough.
Open notification.rake
, and include a conditional where you're asking rails to execute the code block only if today is Sunday.
# lib/tasks/notification.rake desc "Sends SMS notification to employees asking them to log if they had overtime or not" task sms: :environment do if Time.now.sunday? end end
We'll implement it in the next video.