Tôi đã làm việc trên hệ thống bỏ phiếu dài. tôi dùng bình + mongokit + cần tây + gevent.Tôi muốn sử dụng gevent.evnet vào celery.task
Khi quá trình trong nhiệm vụ cần tây, được thực hiện gevent.event.set() công việc không thực hiện. vì vậy tôi muốn giúp tìm ra nó (Lý do tại sao tôi sử dụng gevent cùng lúc với cần tây, có quá trình rất lớn để giải quyết trong hệ thống Thông báo)
đây là mã mẫu của tôi.
#server.py
@celery.task()
def doing_task(uid, message):
notification = Notification() # this is a notification Model
notification.add(request.args.get('to'), some_notification)
app.event.set()
app.event.clear()
@app.route('/main')
def main():
return render_template('main.html')
@app.route('/set')
def set():
doing_task.delay(request.args.get('uid'), 'Notify')
return 'OK'
@app.route('/poll')
def poll():
uid = request.args.get('uid')
app.event.wait()
if is_authorized(uid): #uid 1 is a authorized account
return Notification().get(uid)
#main.html
<body>
<button>Click me</button>
</body>
<script>
$('button').click(function(e) {
$.ajax({
'url': '/set',
'data': 'uid=1',
'success': function(data) {
console.log(data);
}
});
e.preventDefault();
});
var poll = function() {
return $.ajax({
'url': '/poll',
'method': 'get',
'async':true,
'dataType': 'json',
'timeout': 10000,
'success': function(data) {
console.log(data);
setTimeout(poll, 50);
},
'error':function (req,sta,er){
setTimeout(poll, 3000);
},
});
};
poll()
</script>