Skip to content

Commit

Permalink
update cleanDownload.py
Browse files Browse the repository at this point in the history
  • Loading branch information
staugur committed Feb 21, 2019
1 parent cb5211e commit 87129f5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ FROM registry.cn-beijing.aliyuncs.com/staugur/python:supervisor
MAINTAINER taochengwei <staugur@saintic.com>
ADD src /Tdi
ADD supervisord.conf /etc/supervisord.conf
RUN yum install -y gcc python-devel libffi-devel && pip install -r /Tdi/requirements.txt && chmod +x /Tdi/cleanDownload.py
RUN yum install -y gcc python-devel libffi-devel && pip install -r /Tdi/requirements.txt && chmod +x /Tdi/cleanDownload.py && ln -sf /Tdi/cleanDownload.py /usr/bin/cleanDownload.py
WORKDIR /Tdi
ENTRYPOINT ["supervisord", "-c", "/etc/supervisord.conf"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
3. 中心端定时检测成员端<ping>,查询其可用性、磁盘、负载、内存,并更新状态。
4. 用户请求时,中心端根据成员端状态和资源计算是否可用,然后从可用列表中随机分配。
5. 程序收到下载请求后,放入异步任务队列,下载完成后回调给中心端,实现提醒、记录等。
6. 定时执行`cleanDownload.py`脚本,清理已过期的压缩文件。

## 部署:

Expand Down
3 changes: 2 additions & 1 deletion src/cleanDownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


def execute_cleanDownload(hours=12):
downloadDir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "downloads")
downloadDir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "downloads")
for uifn in os.listdir(downloadDir):
filepath = os.path.join(downloadDir, uifn)
if os.path.isfile(filepath) and os.path.splitext(uifn)[-1] == ".zip":
Expand All @@ -40,6 +40,7 @@ def execute_cleanDownload(hours=12):
data = rc.hgetall(uifn)
if data and isinstance(data, dict):
resp = try_request(data["CALLBACK_URL"], timeout=5, params=dict(Action="SECOND_STATUS"), data=dict(uifn=uifn))
print("Update expired status for %s, resp is %s" %(uifn, resp))
if resp.get("code") == 0:
rc.delete(uifn)
except Exception, e:
Expand Down
4 changes: 2 additions & 2 deletions src/qf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def DownloadBoard(downloadDir, uifnKey, site, board_id, uifn, board_pins, etime,
# 存入缓存数据
pipe = rc.pipeline()
pipe.hmset(uifn, dict(etime=etime, CALLBACK_URL=CALLBACK_URL))
pipe.expireat(uifn, timestamp_after_timestamp(int(etime), hours=1))
pipe.expireat(uifn, timestamp_after_timestamp(etime, hours=1))
try:
pipe.execute()
except:
Expand Down Expand Up @@ -85,7 +85,7 @@ def _download_img(pin, retry=True):
# 检测压缩文件大小
size = formatSize(os.path.getsize(uifn))
# 删除临时画板目录
# shutil.rmtree(board_id)
shutil.rmtree(board_id)
logger.info("DownloadBoard move over, delete lock and %s" % board_id)
# 计算总共下载用时
dtime = "%.2f" % (time.time() - stime)
Expand Down

0 comments on commit 87129f5

Please sign in to comment.