gtfsrt_concepcion/sync.py

22 lines
621 B
Python
Raw Normal View History

2023-09-16 12:07:33 -03:00
# coding: utf-8
from updater.model.feed import init_db, db, engine
2023-10-01 21:28:17 -03:00
from updater.main import sync_db, log, estado_maximo
2023-09-16 12:07:33 -03:00
import time
2023-10-01 21:28:17 -03:00
import random
2023-09-16 12:07:33 -03:00
if __name__ == '__main__':
init_db(db, engine)
doki = int(time.time()) + 600
2023-10-01 21:28:17 -03:00
time.sleep(random.randint(1, 30)) #random wait
2023-09-16 12:07:33 -03:00
while True:
if not sync_db():
i = int(time.time())
if i >= doki:
doki = i + 600
log.info('Heartbeat')
2023-10-01 21:28:17 -03:00
if estado_maximo == 0:
time.sleep(random.randint(10, 30)) #more randomness
2023-09-16 12:07:33 -03:00
else:
doki = int(time.time()) + 600