-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
34 lines (25 loc) · 921 Bytes
/
main.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
import json
import time
from sqlalchemy.sql.functions import now
from mq import mq
from utils import Logger
logger = Logger.get_logger(__name__)
def receive_msg(ch, method, properties, body):
from db_api import db
logger.info('received msg')
proxy = json.loads(body.decode('utf8'))
checked_proxy = {'is_good': proxy.get('is_good', 0), 'check_at': now(), 'send_to_mq': None}
db.save_checked_proxy(proxy.get('id'), checked_proxy)
ch.basic_ack(delivery_tag=method.delivery_tag)
def update_checked_proxy():
mq.connect_to_queue('checked_proxy')
mq.channel.basic_qos(prefetch_count=1)
mq.channel.basic_consume(queue='checked_proxy', on_message_callback=receive_msg)
mq.channel.start_consuming()
if __name__ == '__main__':
while True:
try:
update_checked_proxy()
except Exception as ex:
logger.error(str(ex))
time.sleep(3)