Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

1031 fix missed emails #1115

Merged
merged 1 commit into from
Feb 6, 2015
Merged

1031 fix missed emails #1115

merged 1 commit into from
Feb 6, 2015

Conversation

esoterik
Copy link
Collaborator

Resolves #1031

@@ -6,7 +6,8 @@ task delete_missed_reservations: :environment do
unless AppConfig.first.blank? || AppConfig.first.res_exp_time.blank?
time = AppConfig.first.res_exp_time
missed_reservations = Reservation.where(
'checked_out IS NULL and due_date < ?', Date.current - time.days)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this only delete past reservations that weren't processed requests? In that case, all requests will just pile up in our database. We might want to approach this by dealing with the mailer task.

@orenyk
Copy link
Contributor

orenyk commented Jan 30, 2015

Ok, this exposed a fundamental issue with our dealings with missed reservations. We currently only send the missed reservation e-mail when the reservation is being deleted, not when it's been missed (since there might be something other than zero in AppConfig.first.res_exp_time). I'd recommend refactoring this into two separate rake tasks - one to send the e-mail (which excludes requests) and one to actually delete missed reservations or denied/missed requests. Thoughts?

@esoterik
Copy link
Collaborator Author

working on that now

@esoterik
Copy link
Collaborator Author

We want all reservations (regardless of approval status) past the expiration time to be deleted, correct?
And emails should only be sent out for missed reservations that were approved?

@orenyk
Copy link
Contributor

orenyk commented Jan 30, 2015

Almost. Basically, any reservation that has not been checked out before its due date and its due date is however many days ago as set in AppConfig.first.res_exp_time should be deleted, regardless of approval status. We should also send out e-mails for such reservations that were either not requests (i.e. approval_status = 'auto') or were approved (i.e. approval_status = 'approved') on the day after the due date (i.e. once they've been missed). Does that make sense?

@esoterik
Copy link
Collaborator Author

Yes. I just want to clarify one thing: we only want to send emails when the reservation is missed, and not when it is deleted, right? Or are we sending emails both the day after the reservation is missed and then the missed reservation is deleted?

@orenyk
Copy link
Contributor

orenyk commented Feb 1, 2015

Yup, no need to send an e-mail when the reservations are deleted.

@esoterik
Copy link
Collaborator Author

esoterik commented Feb 1, 2015

Okay, this should be working now!

# get all reservations that are approved and missed, send an email to
# user to inform them
missed_reservations = Reservation.where(
"checked_out IS NULL and approval_status <> 'denied' and due_date < ? ",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to exclude requests that were both denied (i.e. approval_status = 'denied') and those that simply weren't processed (i.e. approval_status = 'requested'). That means that we'll only be including those with an approval status of auto or approved. You can structure the query either way, I'd say it's probably better to use the equality since that way we don't unexpectedly send e-mails to people if we introduce a different approval_status option (e.g. pending).

@orenyk
Copy link
Contributor

orenyk commented Feb 1, 2015

Much better! I left a few inline comments; one thing that also needs to be done is to add the new rake task to our cron jobs so that it gets run nightly. The relevant file is config/schedule.rb, just add a call to the new rake task in the nightly group. This will also have to be done in the Heroku branch (#1103), I'll handle that myself since I'm guessing this will be merged into master before that one will.

@orenyk orenyk mentioned this pull request Feb 1, 2015
@esoterik
Copy link
Collaborator Author

esoterik commented Feb 5, 2015

Implemented changes from the comments, except I wasn't able to use the update method because the Reservation model has a different update method defined; I used update_attributes instead.

@orenyk
Copy link
Contributor

orenyk commented Feb 5, 2015

Good catch; I know the method as update_attributes but they changed the "official" name in Rails 4 to update. I'll check out your changes tonight and hopefully we can merge this in.

@esoterik
Copy link
Collaborator Author

esoterik commented Feb 6, 2015

@orenyk has code reviewed this

test if a pending reservation will be deleted

missed reservations query ignores pending reservations

remove test for deleting pending reservations

tests for sending emails for missed reservations

renamed UserMailer#missed_reservation_deleted_notification to missed_reservation_notification

new task for emailing about missed reservations

delete_missed_reservations task no longer sends emails

updated test to reflect only sending missed rervation emails for approved and auto reservations

updated missed reservations email task to query for reservations that were approved or auto only

check AppConfig to see if we want to send emails about missed reservations

added email_missed_reservations task to cron jobs

use scopes

don't spam users

Use rails logger instead of puts
@esoterik esoterik force-pushed the 1031_fix_missed_emails branch from 3efdfcb to bad8c03 Compare February 6, 2015 03:03
orenyk added a commit that referenced this pull request Feb 6, 2015
@orenyk orenyk merged commit 8b275cc into master Feb 6, 2015
@orenyk orenyk deleted the 1031_fix_missed_emails branch March 30, 2015 16:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Open requests being included in missed reservation e-mails
2 participants