-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_run.py
46 lines (38 loc) · 1.24 KB
/
auto_run.py
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
40
41
42
43
44
45
46
"""Run script during intervals."""
import datetime
import logging
import sys
import traceback
from multiprocessing.pool import ThreadPool
import multiprocessing
from threading import Thread
from apscheduler.schedulers.blocking import BlockingScheduler
from scrapper import run, contador
def scheduler_config(fn, args, start):
return {
"func": fn,
"args": args,
"trigger": "interval",
"minutes": contador.get_config()["script"]["frecuencia [minutos]"],
"next_run_time": start,
}
if __name__ == "__main__":
scheduler = BlockingScheduler()
try:
mode = sys.argv[1]
if mode == "multiple":
workers = multiprocessing.cpu_count()
pool = ThreadPool(workers)
users = None
scheduler.add_job(
**scheduler_config(
run.multiple, (pool, users, True), datetime.datetime.now()
)
)
scheduler.start()
else:
contador.info_log.error(f"mode value error: can't be <{mode}>")
except IndexError:
# no value passed, run single thread script
scheduler.add_job(**scheduler_config(run.single, None, datetime.datetime.now()))
scheduler.start()