Skip to content

Commit 5fb0fdf

Browse files
committed
Move thread lock up + long running backup check
1 parent 8bf4258 commit 5fb0fdf

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

nimletter.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ proc scheduleStart() {.thread.} =
110110

111111
every(minutes=30, id="tick", throttle=2):
112112
echo "Backup schedule check: " & $now() & " on thread " & $getThreadId()
113-
checkAndSendScheduledEmails(minutesBack = 60, until = now() - initDuration(minutes = 10))
113+
checkAndSendScheduledEmails(minutesBack = 60, until = now() - initDuration(minutes = 10), isBackupRun = true)
114114

115115

116116

nimletter.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.4.6"
3+
version = "0.4.7"
44
author = "ThomasTJdev"
55
description = "Newsletter"
66
license = "AGPL v3"

src/scheduling/check_schedule.nim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ initLock(gPendingEmailLock)
2222

2323

2424

25-
proc checkAndSendScheduledEmails*(minutesBack = 5, until = now().utc) =
25+
proc checkAndSendScheduledEmails*(minutesBack = 5, until = now().utc, isBackupRun = false) =
2626

2727
acquire(gPendingEmailLock)
2828

@@ -54,7 +54,7 @@ proc checkAndSendScheduledEmails*(minutesBack = 5, until = now().utc) =
5454
where = [
5555
"pending_emails.scheduled_for <= ?",
5656
"pending_emails.scheduled_for >= ?",
57-
"pending_emails.status = 'pending'"
57+
"pending_emails.status = 'pending'" & (if isBackupRun: " OR pending_emails.status = 'inprogress'" else: "")
5858
]
5959
),
6060
rightNow,
@@ -73,6 +73,8 @@ proc checkAndSendScheduledEmails*(minutesBack = 5, until = now().utc) =
7373
]
7474
), "inprogress", rightNow, timeThreshold)
7575

76+
release(gPendingEmailLock)
77+
7678
for pendingEmail in pendingEmails:
7779
echo "Sending email: " & pendingEmail[0]
7880

@@ -94,4 +96,3 @@ proc checkAndSendScheduledEmails*(minutesBack = 5, until = now().utc) =
9496
manualSubject: pendingEmail[14]
9597
)
9698

97-
release(gPendingEmailLock)

0 commit comments

Comments
 (0)