0
0
Ruby on Railsframework~30 mins

Scheduled jobs in Ruby on Rails - Mini Project: Build & Apply

Choose your learning style9 modes available
Scheduled Jobs with Rails
📖 Scenario: You are building a simple Rails app that sends daily reminder emails to users. To do this, you need to set up a scheduled job that runs every day and triggers the email sending process.
🎯 Goal: Learn how to create a scheduled job in Rails using Active Job and a scheduler gem. You will set up the job, configure the schedule, and complete the job logic.
📋 What You'll Learn
Create a job class called DailyReminderJob
Set a schedule variable for the job to run daily at 9 AM
Implement the job's perform method to call User.send_daily_reminders
Configure the scheduler to run the job at the specified time
💡 Why This Matters
🌍 Real World
Scheduled jobs are used in real apps to automate tasks like sending emails, cleaning databases, or generating reports without manual intervention.
💼 Career
Understanding scheduled jobs is essential for backend developers and DevOps roles to maintain reliable and automated workflows.
Progress0 / 4 steps
1
Create the job class
Create a job class called DailyReminderJob that inherits from ApplicationJob.
Ruby on Rails
Need a hint?

Use class DailyReminderJob < ApplicationJob and set queue_as :default.

2
Set the schedule time
Add a variable called SCHEDULE_TIME in DailyReminderJob and set it to '9:00' to represent 9 AM daily.
Ruby on Rails
Need a hint?

Define SCHEDULE_TIME = '9:00' inside the class.

3
Implement the perform method
Inside DailyReminderJob, add a perform method that calls User.send_daily_reminders.
Ruby on Rails
Need a hint?

Define def perform and inside call User.send_daily_reminders.

4
Configure the scheduler
In your scheduler configuration file (e.g., config/schedule.rb), add a job to run DailyReminderJob.perform_later every day at DailyReminderJob::SCHEDULE_TIME.
Ruby on Rails
Need a hint?

Use every 1.day, at: DailyReminderJob::SCHEDULE_TIME do and inside call runner "DailyReminderJob.perform_later".