winupdate task fixes

This commit is contained in:
wh1te909 2020-09-11 04:16:21 +00:00
parent f5e7adf17c
commit b2bca5fe1c
3 changed files with 41 additions and 23 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.1.1 on 2020-09-11 04:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('winupdate', '0007_winupdatepolicy_run_time_day'),
]
operations = [
migrations.AlterField(
model_name='winupdatepolicy',
name='run_time_day',
field=models.IntegerField(choices=[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23), (24, 24), (25, 25), (26, 26), (27, 27), (28, 28), (29, 29), (30, 30), (31, 31)], default=1),
),
]

View File

@ -21,7 +21,7 @@ AUTO_APPROVAL_CHOICES = [
RUN_TIME_HOUR_CHOICES = [(i, dt.time(i).strftime("%I %p")) for i in range(24)]
RUN_TIME_DAY_CHOICES = [(i, dt.date(1970, 1, 1).strftime("%-d")) for i in range(31)]
RUN_TIME_DAY_CHOICES = [(i + 1, i + 1) for i in range(31)]
REBOOT_AFTER_INSTALL_CHOICES = [
("never", "Never"),

View File

@ -60,41 +60,41 @@ def check_agent_update_schedule_task():
hour = int(agent_localtime_now.strftime("%-H"))
day = int(agent_localtime_now.strftime("%-d"))
# get agent last installed time in local time zone
last_installed = agent.patches_last_installed.astimezone(timezone)
if agent.patches_last_installed:
# get agent last installed time in local time zone
last_installed = agent.patches_last_installed.astimezone(timezone)
# check if patches were already run for this cycle and exit if so
if last_installed and last_installed.strftime(
"%d/%m/%Y"
) == agent_localtime_now.strftime("%d/%m/%Y"):
return
# check if patches were already run for this cycle and exit if so
if last_installed.strftime("%d/%m/%Y") == agent_localtime_now.strftime(
"%d/%m/%Y"
):
return
# check if schedule is set to daily/weekly
if patch_policy.run_time_frequency == "weekly":
# check if patches were scheduled to run today
if weekday in patch_policy.run_time_days:
# check if patches are past due
if patch_policy.run_time_hour < hour:
install = True
# check if schedule is set to daily/weekly and if now is the time to run
if (
patch_policy.run_time_frequency == "daily"
and weekday in patch_policy.run_time_days
and patch_policy.run_time_hour == hour
):
install = True
elif patch_policy.run_time_frequency == "monthly":
if patch_policy.run_time_day > 28:
months_with_30_days = [3, 6, 9, 11]
current_month = agent_localtime_now.strftime("%-m")
current_month = int(agent_localtime_now.strftime("%-m"))
if current_month == 2:
patch_policy.run_time_day = 28
elif current_month in months_with_30_days:
patch_policy.run_time_day = 30
# check if patches were scheduled to run today
if day == patch_policy.run_time_day:
# check if patches are past due
if patch_policy.run_time_hour < hour:
install = True
# check if patches were scheduled to run today and now
if (
day == patch_policy.run_time_day
and patch_policy.run_time_hour == hour
):
install = True
if install:
# initiate update on agent asynchronously and don't worry about ret code