forked from mlj0381/printyun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
executable file
·42 lines (31 loc) · 1.24 KB
/
worker.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
import os
import redis, subprocess
from rq import Worker, Queue, Connection, job
listen = ['to_pdf']
redis_url = os.getenv('REDISTOGO_URL', 'redis://:123456@localhost:6379')
conn = redis.Redis.from_url(redis_url)
que = Queue(connection=conn, name='to_pdf')
# 转换pdf
# 定义文件转换后保存的目录
# basepath = os.path.abspath(os.path.dirname(__file__))
FileSaveDir = os.path.join('/root/print/app/static/Upload_Files')
def switch_topdf(filename, current_Id):
# cmd = "libreoffice --headless --convert-to pdf:writer_pdf_Export {} --outdir {}".format(filename, FileSaveDir) #mac linux
cmd = "soffice --headless --convert-to pdf:writer_pdf_Export {} --outdir {}".format(filename, FileSaveDir) # win
print(cmd)
try:
returnCode = subprocess.call(cmd, shell=True)
# returnCode = os.system(cmd)
if returnCode != 0:
raise IOError("{} failed to switch".format(filename))
except Exception:
conn.publish(current_Id, 'None')
return 1
else:
conn.publish(current_Id, 'OK')
return 0
if __name__ == '__main__':
with Connection(conn):
worker = Worker(list(map(Queue, listen)))
worker.work()
# take_message.