Sohail: Fix bugs preventing 4am cron job from sending follow-up emails#2051
Open
sohailuddinsyed wants to merge 2 commits intodevelopmentfrom
Open
Sohail: Fix bugs preventing 4am cron job from sending follow-up emails#2051sohailuddinsyed wants to merge 2 commits intodevelopmentfrom
sohailuddinsyed wants to merge 2 commits intodevelopmentfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Follow-up fix to PR #1788 - Blue Square Email Automation. After the original PR was merged into production, the 12 AM blue square assignment emails worked correctly, but the 4 AM follow-up emails were not being sent.
Related PRs
Main Changes Explained
1. Fixed Critical Time Range Bug in
completeHoursAndMissedSummaryIssue: Function was checking the CURRENT week's hours instead of LAST week's hours.
Impact: When running at 4 AM on Sunday (start of new week), users had only logged 0-4 hours in the current week, causing
timeNotMetto always betrue. This prevented emails from being sent to users who completed their hours but forgot their summary.Fix: Changed from
pdtStartOfCurrentWeek/pdtEndOfCurrentWeektopdtStartOfLastWeek/pdtEndOfLastWeek.Additional Fix: Corrected array bounds check from
length >= 1tolength > 1to prevent accessingweeklySummaries[1]when array only has 1 element.2. Fixed Critical Time Range Bug in
inCompleteHoursEmailFunctionIssue: Function was checking the CURRENT week's hours instead of LAST week's hours.
Impact: Same as above - users appeared to have completed 0% of hours when checked at 4 AM Sunday, causing incorrect email logic evaluation.
Fix: Changed from
pdtStartOfCurrentWeek/pdtEndOfCurrentWeektopdtStartOfLastWeek/pdtEndOfLastWeek.3. Verified
weeklyBlueSquareReminderFunction(No Bugs Found)Status: This function was already correctly checking last week's hours.
Enhancement: Added comprehensive logging to help debug why emails might not be sent (function is intentionally selective based on user tenure and infringement history).
4. Added Comprehensive Logging
Added detailed console logs to all three functions for production debugging:
Root Cause Analysis
The 12 AM job (
assignBlueSquareForTimeNotMet) was already correctly checking last week's hours, which is why those emails worked. However, the 4 AM follow-up functions were inadvertently checking the current week (which just started 4 hours ago), causing them to fail their conditions and skip sending emails.Expected Behavior After Fix
At 12:00 AM PST Sunday
assignBlueSquareForTimeNotMetruns:At 4:00 AM PST Sunday (4 hours later)
completeHoursAndMissedSummary:inCompleteHoursEmailFunction:weeklyBlueSquareReminderFunction:How to Test
Use Test Script (Recommended)
Important
Follow instructions in the test script documentation from PR #1788.
What to Verify
Important Notes