Skip to content

Commit e5dacd5

Browse files
committed
Randomly spread out the next run of scheduled tasks
1 parent c43f2de commit e5dacd5

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

backend/donations/management/commands/schedule_ngos_check.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from datetime import timedelta
3+
from random import randint
34

45
from django.utils import timezone
56
from django_q.models import Schedule
@@ -18,7 +19,7 @@ class Command(SchedulerCommand):
1819
"schedule_type": Schedule.MINUTES,
1920
"minutes": 12,
2021
"repeats": -1,
21-
"next_run": timezone.now() + timedelta(minutes=0),
22+
"next_run": timezone.now() + timedelta(seconds=randint(0, 8 * 60)),
2223
}
2324

2425
def handle(self, *args, **kwargs):

backend/donations/management/commands/schedule_stats_generator_ngos.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from datetime import timedelta
3+
from random import randint
34

45
from django.utils import timezone
56
from django_q.models import Schedule
@@ -20,7 +21,7 @@ class Command(SchedulerCommand):
2021
"schedule_type": Schedule.MINUTES,
2122
"minutes": 15,
2223
"repeats": -1,
23-
"next_run": timezone.now() + timedelta(minutes=0),
24+
"next_run": timezone.now() + timedelta(seconds=randint(0, 10 * 60)),
2425
}
2526

2627
choices = [StatsChoices.NGOS_REGISTERED, StatsChoices.NGOS_ACTIVE, StatsChoices.NGOS_WITH_NGOHUB]

backend/donations/management/commands/schedule_stats_generator_ngos_yearly.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from datetime import timedelta
3+
from random import randint
34

45
from django.utils import timezone
56
from django_q.models import Schedule
@@ -20,7 +21,7 @@ class Command(SchedulerCommand):
2021
"schedule_type": Schedule.MINUTES,
2122
"minutes": 15,
2223
"repeats": -1,
23-
"next_run": timezone.now() + timedelta(minutes=0),
24+
"next_run": timezone.now() + timedelta(seconds=randint(0, 10 * 60)),
2425
}
2526

2627
choices = [

backend/donations/management/commands/schedule_stats_generator_redirections.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from datetime import timedelta
3+
from random import randint
34

45
from django.utils import timezone
56
from django_q.models import Schedule
@@ -19,5 +20,5 @@ class Command(SchedulerCommand):
1920
"schedule_type": Schedule.MINUTES,
2021
"minutes": 5,
2122
"repeats": -1,
22-
"next_run": timezone.now() + timedelta(minutes=0),
23+
"next_run": timezone.now() + timedelta(seconds=randint(0, 3 * 60)),
2324
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
2+
from datetime import timedelta
23

4+
from django.utils import timezone
35
from django_q.models import Schedule
46

57
from utils.common.commands import SchedulerCommand
@@ -8,12 +10,13 @@
810

911

1012
class Command(SchedulerCommand):
11-
help = "Schedule a session cleanup task to run every day at 5:30 AM."
13+
help = "Schedule a session cleanup task to run once a day"
1214

1315
command_name: str = "clearsessions"
1416

1517
schedule_name = "CLEANUP_SESSIONS"
1618
schedule_details = {
1719
"schedule_type": Schedule.DAILY,
1820
"repeats": -1,
21+
"next_run": timezone.now() + timedelta(minutes=40),
1922
}

backend/utils/management/commands/schedule_auditlog_cleanup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ class Command(SchedulerCommand):
1818
schedule_details = {
1919
"schedule_type": Schedule.DAILY,
2020
"repeats": -1,
21-
"next_run": timezone.now() + timedelta(minutes=7),
21+
"next_run": timezone.now() + timedelta(minutes=50),
2222
}

0 commit comments

Comments
 (0)