Add approval robot.
This commit is contained in:
parent
8dfe21acd4
commit
f24f38ead4
|
@ -1,3 +1,4 @@
|
|||
import threading,datetime,random,time
|
||||
from model import db,User,ApplyMsg
|
||||
from userManager import administration_required
|
||||
|
||||
|
@ -54,3 +55,28 @@ class ApplicationMgr:
|
|||
applymsg.status = "Rejected"
|
||||
db.session.commit()
|
||||
return {"success":"true"}
|
||||
|
||||
class ApprovalRobot(threading.Thread):
|
||||
|
||||
def __init__(self,maxtime=3600):
|
||||
threading.Thread.__init__(self)
|
||||
self.stop = False
|
||||
self.interval = 20
|
||||
self.maxtime = maxtime
|
||||
|
||||
def stop(self):
|
||||
self.stop = True
|
||||
|
||||
def run(self):
|
||||
while not self.stop:
|
||||
applymsgs = ApplyMsg.query.filter_by(status="Processing").all()
|
||||
for msg in applymsgs:
|
||||
secs = (datetime.datetime.now() - msg.time).seconds
|
||||
ranint = random.randint(self.interval,self.maxtime)
|
||||
if secs >= ranint:
|
||||
msg.status = "Agreed"
|
||||
user = User.query.filter_by(username=msg.username).first()
|
||||
if user is not None:
|
||||
user.beans += msg.number
|
||||
db.session.commit()
|
||||
time.sleep(self.interval)
|
||||
|
|
|
@ -998,6 +998,8 @@ if __name__ == '__main__':
|
|||
master_collector.start()
|
||||
logger.info("master_collector started")
|
||||
G_applicationmgr = beansapplicationmgr.ApplicationMgr()
|
||||
approvalrbt = beansapplicationmgr.ApprovalRobot(120)
|
||||
approvalrbt.start()
|
||||
|
||||
# server = http.server.HTTPServer((masterip, masterport), DockletHttpHandler)
|
||||
logger.info("starting master server")
|
||||
|
|
|
@ -247,14 +247,14 @@ class ApplyMsg(db.Model):
|
|||
number = db.Column(db.Integer)
|
||||
reason = db.Column(db.String(600))
|
||||
status = db.Column(db.String(10))
|
||||
time = db.Column(db.String(10))
|
||||
time = db.Column(db.DateTime(10))
|
||||
|
||||
def __init__(self,username, number, reason):
|
||||
self.username = username
|
||||
self.number = number
|
||||
self.reason = reason
|
||||
self.status = "Processing"
|
||||
self.time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
self.time = datetime.now()
|
||||
|
||||
def __repr__(self):
|
||||
return "{\"id\":\"%d\", \"username\":\"%s\", \"number\": \"%d\", \"reason\":\"%s\", \"status\":\"%s\", \"time\":\"%s\"}" % (self.id, self.username, self.number, self.reason, self.status, self.time)
|
||||
return "{\"id\":\"%d\", \"username\":\"%s\", \"number\": \"%d\", \"reason\":\"%s\", \"status\":\"%s\", \"time\":\"%s\"}" % (self.id, self.username, self.number, self.reason, self.status, self.time.strftime("%Y-%m-%d %H:%M:%S"))
|
||||
|
|
Loading…
Reference in New Issue