1 Star 0 Fork 2

凹凸曼打小怪兽/wenjian

forked from banzhuanxiaodoubi/wenjian 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
job_queue_util.py 1.84 KB
一键复制 编辑 原始数据 按行查看 历史
banzhuanxiaodoubi 提交于 2022-08-02 10:37 . job_queue
import os
import logging
import queue
from time import sleep
from flask import json, current_app, app
from messenger.apps.vmachine.handlers import CreateVmachine
from messenger.utils.response_util import RET
class Task(object):
def __init__(self, priority_queue_job_param):
self._priority = priority_queue_job_param.priority
self._job_type = priority_queue_job_param.job_type
self._time = priority_queue_job_param.sub_time
self.body = priority_queue_job_param.body
self.auth = priority_queue_job_param.auth
def __str__(self):
return "Task(priority={}, name={}, time={}).".format(self._priority, self._job_type, self._time)
def __lt__(self, other):
if self._priority != other._priority:
return self._priority < other._priority
else:
return self._time < other._time
class JobQueue():
instance = None
init_flat = False
def __new__(cls, *args, **kwargs):
if cls.instance is None:
cls.instance = super().__new__(cls)
return cls.instance
def __init__(self):
if self.init_flat == True:
return
self.queue = queue.PriorityQueue()
self.init_flat = True
tsq = JobQueue().queue
class CreateVmachineInCelery(CreateVmachine):
def __init__(self, auth, body):
super().__init__(auth, body)
@property
def logger(self):
return logging
def consume_job():
while True:
if tsq.empty():
logging.info("empty queue,waiting for job..")
else:
task = tsq.get()
while True:
_resp = CreateVmachineInCelery(task.auth, task.body).install()
_resp = json.loads(_resp.data.decode('UTF-8'))
if _resp.get("error_code") == RET.OK:
tsq.task_done()
break
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/concave-convex-manda/wenjian.git
git@gitee.com:concave-convex-manda/wenjian.git
concave-convex-manda
wenjian
wenjian
master

搜索帮助