| 1 |
from threading import Event, Thread |
| 2 |
|
| 3 |
from cvdupdate.cvdupdate import CVDUpdate |
| 4 |
|
| 5 |
def start(interval: int) -> None: |
| 6 |
"""Spawn a thread to update the AV db after "interval" seconds |
| 7 |
:param interval: the interval in seconds between 2 updates of the db |
| 8 |
""" |
| 9 |
if interval > 0: |
| 10 |
Thread(target=_update, daemon=True, args=[interval]).start() |
| 11 |
|
| 12 |
|
| 13 |
def _update(interval: int) -> None: |
| 14 |
"""Don't call this directly |
| 15 |
|
| 16 |
Updates the AV db after every "interval" seconds when it was started |
| 17 |
:param interval: the interval in seconds between 2 updates of the db |
| 18 |
""" |
| 19 |
ticker = Event() |
| 20 |
m = CVDUpdate() |
| 21 |
m.logger.info(f"Updating the database every {interval} seconds") |
| 22 |
while not ticker.wait(interval): |
| 23 |
errors = m.db_update(debug_mode=True) |
| 24 |
if errors > 0: |
| 25 |
m.logger.error("Failed to fetch updates from ClamAV databases") |