mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
Merge branch 'offsetfix' into 'master'
Cron Offset Fix See merge request allianceauth/allianceauth!1678
This commit is contained in:
commit
7483fcb876
29
allianceauth/crontab/migrations/0001_initial.py
Normal file
29
allianceauth/crontab/migrations/0001_initial.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Generated by Django 4.2.16 on 2025-01-20 06:16
|
||||||
|
|
||||||
|
import allianceauth.crontab.models
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='CronOffset',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('minute', models.FloatField(default=allianceauth.crontab.models.random_default, verbose_name='Minute Offset')),
|
||||||
|
('hour', models.FloatField(default=allianceauth.crontab.models.random_default, verbose_name='Hour Offset')),
|
||||||
|
('day_of_month', models.FloatField(default=allianceauth.crontab.models.random_default, verbose_name='Day of Month Offset')),
|
||||||
|
('month_of_year', models.FloatField(default=allianceauth.crontab.models.random_default, verbose_name='Month of Year Offset')),
|
||||||
|
('day_of_week', models.FloatField(default=allianceauth.crontab.models.random_default, verbose_name='Day of Week Offset')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Cron Offsets',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
0
allianceauth/crontab/migrations/__init__.py
Normal file
0
allianceauth/crontab/migrations/__init__.py
Normal file
@ -19,8 +19,17 @@ def offset_cron(schedule: crontab) -> crontab:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
cron_offset = CronOffset.get_solo()
|
cron_offset = CronOffset.get_solo()
|
||||||
new_minute = [(m + (round(60 * cron_offset.minute))) % 60 for m in schedule.minute]
|
|
||||||
new_hour = [(m + (round(24 * cron_offset.hour))) % 24 for m in schedule.hour]
|
# Stops this shit from happening 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
|
||||||
|
# It is only cosmetic, but still annoying
|
||||||
|
if schedule._orig_minute == '*':
|
||||||
|
new_minute = '*'
|
||||||
|
else:
|
||||||
|
new_minute = [(m + (round(60 * cron_offset.minute))) % 60 for m in schedule.minute]
|
||||||
|
if schedule._orig_hour == '*':
|
||||||
|
new_hour = '*'
|
||||||
|
else:
|
||||||
|
new_hour = [(m + (round(24 * cron_offset.hour))) % 24 for m in schedule.hour]
|
||||||
|
|
||||||
return crontab(
|
return crontab(
|
||||||
minute=",".join(str(m) for m in sorted(new_minute)),
|
minute=",".join(str(m) for m in sorted(new_minute)),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user