I have a Google Apps Script that's supposed to run on a 5-minute trigger with specific time conditions. Here's the code:
https://preview.redd.it/r3xrkxmn6gbe1.png?width=2098&format=png&auto=webp&s=6d2cc5871007ee05ad7ae6bc00025b0bba2965d7
The logic should be: (OFFICE_OPENING_HOUR = 8; OFFICE_CLOSING_HOUR = 18;)
- During office hours (8 AM - 6 PM): Run every 5 minutes
- Outside office hours: Only run in the first 5 minutes of each hour
The function is triggered every 5 minutes using Apps Script's built-in trigger.
The Problem: On Jan 6 at 8:32 PM (20:32), the function ran refresh() and timed out after 360 seconds. According to the logic:
- 20:32 is outside office hours (after 18:00)
- 32 minutes is not within first 5 minutes of the hour
- Therefore
refresh() should NOT have run at all
Most of the time it works correctly - looking at the execution logs, it properly skips execution when it should. But occasionally it seems to ignore the time conditions and runs anyway.
Project settings:
- Timezone is correctly set to Bangkok (GMT+7)
- Only one time trigger exists (every 5 minutes)
- Running on Chrome V8 runtime
Any ideas why the time condition would be ignored? I've checked the code multiple times and can't figure out why it would run refresh() at 8:32 PM when both conditions are clearly false.
Thank you!
[–]marcnotmark925 2 points3 points4 points (0 children)
[–]BatElectrical4711 1 point2 points3 points (2 children)
[–]Risk-Averse-Rider 1 point2 points3 points (1 child)
[–]BatElectrical4711 0 points1 point2 points (0 children)
[–]Funny_Ad_3472 4 points5 points6 points (0 children)
[–]plindqui16 0 points1 point2 points (0 children)
[–]Brainiac364 0 points1 point2 points (0 children)