Untitled

 avatar
unknown
python
2 years ago
1.1 kB
4
Indexable
def sync(queue: queues.Queue, lock: synchronize.Lock) -> None:
    log.setup_subprocess_logging(queue)

    try:
        LOG.info(f"source={SOURCE_NAME}: sync start")

        source_engine = db.get_engine(SOURCE_NAME)

        tracker_table = source_db.TrackerTable(SOURCE_NAME)

        main_table = core.MainTable()

        sync_time = CONF.source_frontiir_erp.sync_daily_at
        if sync_time:
            schedule.every().day.at(sync_time).do(
                _sync_with_retry,
                lock,
                source_engine,
                tracker_table,
                main_table,
            )
            while True:
                schedule.run_pending()
                time.sleep(1)
        else:
            _sync_with_retry(
                lock,
                source_engine,
                tracker_table,
                main_table,
            )
    except KeyboardInterrupt:
        do something
    except Exception as e:
        LOG.error(f"source={SOURCE_NAME}: sync failed", exc_info=True)
        deal with e
    finally:
        LOG.info(f"source={SOURCE_NAME}: sync end")
        other cleanup()
Editor is loading...