forked from Jackiebibili/ticket_tracker_api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapps.py
More file actions
39 lines (30 loc) · 1.07 KB
/
apps.py
File metadata and controls
39 lines (30 loc) · 1.07 KB
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
36
37
38
39
from django.apps import AppConfig
from datetime import datetime
from threading import Thread
from multiprocessing import Process
def run_prepare():
# import module inside the child process to prevent execution in the parent process
print(
f"ticket scraping service started at {datetime.now().strftime('%d/%m/%Y %H:%M:%S')}")
# start sender socket
from apps.ticketscraping.schedulers.async_tasks_scheduler import async_tasks_scheduler
conn_thread = Thread(target=async_tasks_scheduler.connect)
conn_thread.start()
# wait for async tasks handler to connect
conn_thread.join()
# start itself (scraping)
from apps.ticketscraping.scraping import start
start()
def run():
# starter
p = Process(target=run_prepare, daemon=True)
p.start()
# start receiver socket
from apps.ticketscraping.connection.asyn_tasks_receiver import run
conn_process = Process(target=run)
conn_process.start()
class MyAppConfig(AppConfig):
name = "apps.startup"
verbose_name = "start tmtracker"
def ready(self):
run()