Skip to content

Commit d016e1a

Browse files
committed
CHANGES:
- DCS updates can now have an update_window to configure times when no DCS update should take place.
1 parent 184632e commit d016e1a

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,19 @@ NODENAME: # this will usually be your hostname
357357
DCS:
358358
installation: '%ProgramFiles%\\Eagle Dynamics\\DCS World Server' # This is your DCS installation. Usually autodetected by the bot.
359359
autoupdate: true # enable auto-update for your DCS servers. Default is false.
360-
announce: # Optional: post a message to Discord after every update
360+
announce: # Optional: post a message to Discord after an update was conducted
361361
channel: 11223344556677
362362
title: DCS has been updated to version {}!
363363
description: 'The following servers have been updated:'
364364
footer: Please make sure you update your DCS client to join!
365365
mention: # Optional mentioning
366366
- Admin
367367
- DCS Admin
368+
update_window: # Optional update window. No update will happen if N is set for the respective time and day.
369+
timezone: Europe/Berlin # Optional timezone, default is the local time of the server.
370+
00-18: YYYYYYY
371+
18-20: YYYYYYN # Do not update DCS on Sundays, 18:00-20:00 LT
372+
20-24: YYYYYYY
368373
use_upnp: true # Do you want to use UPnP to forward your DCS ports automatically? If not set, the global setting will be used.
369374
cloud: true # If you have installed DCS on a NAS or cloud drive, autoupdate and desanitization will only take place once on all your nodes.
370375
desanitize: true # Desanitize your MissionScripting.lua after each update. Default is true.

core/data/impl/nodeimpl.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from core.const import SAVED_GAMES
2424
from core.data.maintenance import ServerMaintenanceManager
2525
from core.translations import get_translation
26+
from datetime import datetime
2627
from discord.ext import tasks
2728
from gzip import BadGzipFile
2829
from migrate import migrate
@@ -35,6 +36,7 @@
3536
from typing import Optional, Union, Awaitable, Callable, Any, cast
3637
from urllib.parse import urlparse, quote
3738
from version import __version__
39+
from zoneinfo import ZoneInfo
3840

3941
from core.autoexec import Autoexec
4042
from core.data.dataobject import DataObjectFactory, DataObject
@@ -1129,11 +1131,31 @@ async def dcs_update(self, *, branch: Optional[str] = None, version: Optional[st
11291131
}
11301132
})
11311133

1134+
def can_update(self):
1135+
update_window = self.locals.get('DCS', {}).get('update_window')
1136+
if update_window:
1137+
now: datetime = datetime.now()
1138+
tz = now.astimezone().tzinfo
1139+
now = now.replace(tzinfo=tz)
1140+
weekday = now.weekday()
1141+
for period, daystate in update_window.items(): # type: str, str
1142+
if period == 'timezone':
1143+
tz = ZoneInfo(daystate)
1144+
continue
1145+
if len(daystate) != 7:
1146+
self.log.error(f"Error in nodes.yaml (update_window): {daystate} has to be 7 characters long!")
1147+
return False
1148+
state = daystate[weekday]
1149+
if utils.is_in_timeframe(now, period, tz):
1150+
return state.upper() == 'Y'
1151+
return True
1152+
11321153
@tasks.loop(minutes=5.0)
11331154
async def autoupdate(self):
11341155
# don't run if an update is currently running
1135-
if self.update_pending:
1156+
if self.update_pending or not self.can_update():
11361157
return
1158+
# Check if we are in the correct time window
11371159
try:
11381160
version = await self.is_dcs_update_available()
11391161
if version:
@@ -1159,7 +1181,7 @@ async def before_autoupdate(self):
11591181

11601182
# check for updates
11611183
new_version = await self.is_dcs_update_available()
1162-
if new_version:
1184+
if new_version and self.can_update():
11631185
await self.dcs_update(version=new_version)
11641186
self.update_pending = False
11651187

plugins/scheduler/commands.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ async def check_server_state(server: Server, config: dict) -> Status:
108108
continue
109109
if len(daystate) != 7:
110110
server.log.error(f"Error in scheduler.yaml: {daystate} has to be 7 characters long!")
111+
break
111112
state = daystate[weekday]
112-
# check, if the server should be running
113+
# check if the server should be running
113114
if (utils.is_in_timeframe(now, period, tz) and state.upper() == 'Y' and
114115
server.status == Status.SHUTDOWN):
115116
return Status.RUNNING

schemas/nodes_schema.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ mapping:
4141
nullable: false
4242
sequence:
4343
- { type: text, nullable: false }
44+
update_window:
45+
type: map
46+
nullable: false
47+
mapping:
48+
timezone: { type: str, nullable: false, range: { min: 1 } }
49+
regex;(^(0?[0-9]|1[0-9]|2[0-4])(:[0-5][0-9])?-(0?[0-9]|1[0-9]|2[0-4])(:?[0-5][0-9])?$): { type: str, pattern: '^[YNP]{7}$', nullable: false }
4450
desanitize: {type: bool, nullable: false}
4551
minimized: {type: bool, nullable: false}
4652
user: {type: str, nullable: false, range: {min: 1}}

0 commit comments

Comments
 (0)