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
import os
import sys
import time
sys.path.append(os.path.dirname(sys.path[0]))
from utils.redis_utils import RedisUtils
from utils.ssh_util import SSHUtil
from utils.common_util import CommonUtil
"""
定时任务执行
"""
def timer():
import threading
# 设置定时器,每5分钟执行一次
threading.Timer(300, timer).start()
client = RedisUtils.getClient()
list_key = "asin_img_path:list"
if client.exists(list_key):
llen = int(client.llen(list_key))
if llen > 100000:
return
print("调度执行中!")
sh = rf"""
/opt/module/spark/bin/spark-submit \
--master yarn \
--driver-memory 2g \
--executor-memory 10g \
--executor-cores 2 \
--num-executors 5 \
--queue spark \
{CommonUtil.__desploy_home__}/script/asin_img_parse_sender.py
"""
client = SSHUtil.get_ssh_client()
SSHUtil.exec_command_async(client, sh, ignore_err=False)
client.close()
pass
if __name__ == '__main__':
# 启动定时器
timer()