make scheduler integrations optional
This commit is contained in:
@@ -24,6 +24,8 @@ services:
|
||||
HA_TOKEN: ${HA_TOKEN:?set HA_TOKEN}
|
||||
OPENWEATHER_API_KEY: ${OPENWEATHER_API_KEY:?set OPENWEATHER_API_KEY}
|
||||
CKAL_XLSX_DIR: /data/ckal-xlsx
|
||||
STRATO_SYNC_ENABLED: ${STRATO_SYNC_ENABLED:-true}
|
||||
BRANDSCHUTZ_MAIL_ENABLED: ${BRANDSCHUTZ_MAIL_ENABLED:-true}
|
||||
volumes:
|
||||
- profile_pictures:/var/www/html/intranet_repo/general_files/profile_pictures
|
||||
- content_news:/var/www/html/intranet_repo/projects/contentpanel/insertion/news
|
||||
|
||||
+68
-9
@@ -37,23 +37,65 @@ def prepare_ssh_key() -> Path:
|
||||
|
||||
|
||||
def calendar_sync():
|
||||
run([PYTHON, str(ROOT / 'ckal_upload_client/client.py')], cwd=ROOT / 'ckal_upload_client')
|
||||
run([PYTHON, str(ROOT / 'pdf_python/create_pdf.py')], cwd=ROOT / 'pdf_python')
|
||||
run(['/bin/bash', str(ROOT / 'pdf_python/pdf_to_png.sh')], cwd=ROOT / 'pdf_python')
|
||||
# CKalender-XLSX verarbeiten
|
||||
run(
|
||||
[PYTHON, str(ROOT / 'ckal_upload_client/client.py')],
|
||||
cwd=ROOT / 'ckal_upload_client'
|
||||
)
|
||||
|
||||
# PDF erzeugen
|
||||
run(
|
||||
[PYTHON, str(ROOT / 'pdf_python/create_pdf.py')],
|
||||
cwd=ROOT / 'pdf_python'
|
||||
)
|
||||
|
||||
# PDF in Dashboard-PNGs umwandeln
|
||||
run(
|
||||
['/bin/bash', str(ROOT / 'pdf_python/pdf_to_png.sh')],
|
||||
cwd=ROOT / 'pdf_python'
|
||||
)
|
||||
|
||||
# STRATO-Synchronisation kann z. B. im DEV deaktiviert werden
|
||||
strato_sync_enabled = os.getenv(
|
||||
'STRATO_SYNC_ENABLED',
|
||||
'true'
|
||||
).strip().lower() in ('1', 'true', 'yes', 'on')
|
||||
|
||||
if not strato_sync_enabled:
|
||||
print('STRATO Sync deaktiviert', flush=True)
|
||||
print('Calendar Sync erfolgreich (ohne STRATO)', flush=True)
|
||||
return
|
||||
|
||||
required('STRATO_SSH_USER')
|
||||
required('STRATO_REMOTE_PATH')
|
||||
|
||||
host = os.getenv('STRATO_SSH_HOST', 'ssh.strato.de')
|
||||
port = os.getenv('STRATO_SSH_PORT', '22')
|
||||
known_hosts = Path(os.getenv('STRATO_KNOWN_HOSTS_FILE', '/run/secrets/known_hosts'))
|
||||
|
||||
known_hosts = Path(
|
||||
os.getenv(
|
||||
'STRATO_KNOWN_HOSTS_FILE',
|
||||
'/run/secrets/known_hosts'
|
||||
)
|
||||
)
|
||||
|
||||
if not known_hosts.is_file():
|
||||
raise RuntimeError(f'known_hosts missing: {known_hosts}')
|
||||
raise RuntimeError(
|
||||
f'known_hosts missing: {known_hosts}'
|
||||
)
|
||||
|
||||
key = prepare_ssh_key()
|
||||
|
||||
if not PDF_OUTPUT.is_file() or PDF_OUTPUT.stat().st_size == 0:
|
||||
raise RuntimeError(f'PDF missing/empty: {PDF_OUTPUT}')
|
||||
raise RuntimeError(
|
||||
f'PDF missing/empty: {PDF_OUTPUT}'
|
||||
)
|
||||
|
||||
run([
|
||||
'/usr/bin/scp', '-O', '-q', '-P', port,
|
||||
'/usr/bin/scp',
|
||||
'-O',
|
||||
'-q',
|
||||
'-P', port,
|
||||
'-i', str(key),
|
||||
'-o', 'IdentitiesOnly=yes',
|
||||
'-o', 'BatchMode=yes',
|
||||
@@ -62,23 +104,40 @@ def calendar_sync():
|
||||
str(PDF_OUTPUT),
|
||||
f"{required('STRATO_SSH_USER')}@{host}:{required('STRATO_REMOTE_PATH')}",
|
||||
])
|
||||
|
||||
print('Calendar Sync erfolgreich', flush=True)
|
||||
|
||||
|
||||
def brandschutz_once_per_month():
|
||||
now = datetime.now()
|
||||
|
||||
if now.day != 1 or now.hour < 8:
|
||||
return
|
||||
|
||||
brandschutz_enabled = os.getenv(
|
||||
'BRANDSCHUTZ_MAIL_ENABLED',
|
||||
'true'
|
||||
).strip().lower() in ('1', 'true', 'yes', 'on')
|
||||
|
||||
if not brandschutz_enabled:
|
||||
print('Brandschutz-Mail deaktiviert', flush=True)
|
||||
return
|
||||
|
||||
marker = STATE_DIR / 'brandschutz-last-attempt'
|
||||
month = now.strftime('%Y-%m')
|
||||
|
||||
if marker.exists() and marker.read_text().strip() == month:
|
||||
return
|
||||
|
||||
# At-most-once: erst markieren, dann ausführen. Bei Fehler manuell prüfen und Marker löschen.
|
||||
# At-most-once: erst markieren, dann ausführen
|
||||
marker.write_text(month + '\n')
|
||||
|
||||
print(f'Brandschutz-Lauf {month}', flush=True)
|
||||
run(['/usr/local/bin/php', '/var/www/html/intranet_repo/projects/brandschutz/brandschutz_cron.php'])
|
||||
|
||||
run([
|
||||
'/usr/local/bin/php',
|
||||
'/var/www/html/intranet_repo/projects/brandschutz/brandschutz_cron.php'
|
||||
])
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user