Story #6 Membership Expiration Reminder & Story #27 Add UI to change when automated emails are sent out | User and Technical Documentation - cseseniordesign/reservations GitHub Wiki
End User Documentation
Dev Testing Instructions
Make sure you are on the most recent version of the dev-membership-expiration-reminder branch.
Change the expiration date of the user with your email address to be either within 24 hours or 72 hours.
In your code editor, navigate to config/initializers/scheduler.rb.
Change the scheduler.cron function syntax to be a minute or two from when you will start the program. Cron syntax is in 24 hour time. The first variable is the minute, and the second is the hour. For example: to set it to send every day at 4:30 pm, you would write the syntax: scheduler.cron '30 16 * * * America/Chicago' do.
Save your changes.
Start your dev environment and navigate to any site page to start the schedule process. Note: if the site is loaded more than once, the console will display an error notifying you that only one instance of scheduler.rb can be running at one time. This is intentional.
Wait until it is the time you entered, and within 10 seconds you should receive an email expiration reminder.
End the program and be sure to change the scheduler.cron function syntax back to the original time.
Technical Documentation
scripts/email_expiring_users.rb
Added variables to specify how many days prior to expiration a reminder should be sent. In the user selection queries, 1 day is subtracted from the specified interval as this is how SQL interprets the dates.
There are now two user selection queries to handle both reminder intervals.
There are two iterative loops to send emails to each user within the constraints specified by the queries.
config/initializers/scheduler.rb
Created an initializers folder which scheduler.rb is located in.
Added highlander gem which prevents multiple instances of the same process from running.
Added rufus-scheduler gem which contains the functions needed for the automated schedule.
Added a scheduled process that runs the email_expiring_users.rb file every day at a specified time using cron.
Added a while loop to prevent the scheduler file from exiting.
config.ru
Added code to start the scheduler on a new thread so the main program doesn't hang waiting for the scheduler to finish (which it never should). The scheduler gets called each time a page is accessed.
models/user.rb
Previously the email template had a space between the user's name and the following period. Added .chop to the email template body to remove the space.
models/expiration_reminder.rb
Added ExpirationReminder model which inherent ActiveRecord to connect this model to the "expiration_reminders" table in the database. This model has two methods to get the first and second reminder values from the database.
scripts/email_expiring_users.rb
Updating this file to retrieve the first and the second reminder values from the expiration reminder model instead of the hardcoded values previously.