Planning the SMS Rake Task Data Flow
In this guide we take a step back and plan out the flow for the rake task as it applies to notifications and sending SMS alerts to employees.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

Since we have our task structure in place, let's decide what we want our task to do. In this video, we are going to plan the data flow for the task, so we can implement it accordingly.

I've seen developers who code the entire functionality in the task, but I think this is bad practice because it becomes really difficult to debug. This is why we are going to have some simple logic here, and anything more complicated, we'll put it in the lib file.

Firstly, we want to schedule this task to run every Sunday at 5pm. Then, we are going to iterate over all employees, but skip admin users because they are the managers. Next, send a message that has instructions and a link to log time. I think that's all it should do.

# lib/tasks/notification.rake

namespace :notification do
  desc "Sends SMS notification to employees asking them to log if they had overtime or not"
  task sms: :environment do
    # 1. Schedule to run at Sunday at 5pm
    # 2. Iterate over all employees
    # 3. Skip AdminUsers
    # 4. Send a message that has instructions and a link to log time
    # User.all.each do |user|
    #   SmsTool.send_sms()
    # end
    # number: "555-555-3323"
    # number: "5555553323"
    # No spaces or dashes
    # exactly 10 characters
    # all characters have to be a number
  end
end

We'll start off with the coding and then, refactor or make changes as we go.

Resources