-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimport_task.py
More file actions
35 lines (29 loc) · 887 Bytes
/
import_task.py
File metadata and controls
35 lines (29 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import asyncio
import threading
from icecream import ic
from time import sleep
from services import ImportService
from dependency import injector
def run_on_start(*args, **argv):
num_retry = 0
max_retry = 5
try:
import_service = injector.get(ImportService)
if import_service is not None:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(import_service.run_import_task())
except Exception as ex:
ic(f"Exception importing data {ex}")
if num_retry < max_retry:
sleep(10)
run_on_start()
def run_background_import():
try:
thread = threading.Thread(target=run_on_start())
thread.start()
except Exception as ex:
ic(f'Run exception on import')
ic(ex)
if __name__ == '__main__':
run_background_import()