浏览代码

no message

libushang 8 月之前
父节点
当前提交
ef79630134
共有 1 个文件被更改,包括 49 次插入40 次删除
  1. 49 40
      jobs/yzy_job.py

+ 49 - 40
jobs/yzy_job.py

@@ -3,6 +3,7 @@
 from datetime import datetime
 from sqlalchemy.orm import Session
 from utils import *
+from utils.redis_util import *
 from models import *
 from exceptions import *
 from database import get_db_local
@@ -12,48 +13,56 @@ from config import settings
 import traceback
 
 def proc():
-    logger.info(datetime.now())
+    lock_key = "yzy_job_proc"
+    if redis_lock(lock_key):
+        logger.info(datetime.now())
 
-    redirect_url = "{}/#/leader/index".format(settings.YJXP_WEB_ROOT_PATH) # 业务页面
-    detail_url = YzyApi.format_redirect_url(redirect_url, "eb4kehgy6wj4qn0jhx1dk6")
-    
-    yzy_user_id = "eb4kehgy6wj4qn0jhx1dk6"  # 暂时写死梦梅的账号
-    description = "预案名称: 茂名市自然灾害救助应急预案\n响应级别: Ⅰ级响应\n消息内容: 单位您好!《茂名市自然灾害救助应急预案》现已全面启动,特此通知您单位迅速响应,全力做好预案工作要点:负责救灾工作宣传报道协调工作。"
-    # ret = YzyApi.send_textcard_message(yzy_user_id, "预案响应消息", description, detail_url)
-    # logger.info(ret)
+        redirect_url = "{}/#/leader/index".format(settings.YJXP_WEB_ROOT_PATH) # 业务页面
+        detail_url = YzyApi.format_redirect_url(redirect_url, "eb4kehgy6wj4qn0jhx1dk6")
+        
+        yzy_user_id = "eb4kehgy6wj4qn0jhx1dk6"  # 暂时写死梦梅的账号
+        description = "预案名称: 茂名市自然灾害救助应急预案\n响应级别: Ⅰ级响应\n消息内容: 单位您好!《茂名市自然灾害救助应急预案》现已全面启动,特此通知您单位迅速响应,全力做好预案工作要点:负责救灾工作宣传报道协调工作。"
+        # ret = YzyApi.send_textcard_message(yzy_user_id, "预案响应消息", description, detail_url)
+        # logger.info(ret)
+
+        data = {
+            "yzy_userid": yzy_user_id,
+            "mobile": "13528373954",
+            "content": description,
+            "recorded_by": 1,
+            "detail_url": detail_url,
+            "foreign_key": "1",
+            "from_scenario": "yjya",
+            "title": "预案响应消息"
+        }
 
-    data = {
-        "yzy_userid": yzy_user_id,
-        "mobile": "13528373954",
-        "content": description,
-        "recorded_by": 1,
-        "detail_url": detail_url,
-        "foreign_key": "1",
-        "from_scenario": "yjya",
-        "title": "预案响应消息"
-    }
+        db = get_db_local()
+        YzyApi.add_to_msg_queue(db, data)
+        db.close()
 
-    db = get_db_local()
-    YzyApi.add_to_msg_queue(db, data)
-    db.close()
+        redis_unlock(lock_key)
 
 def yzy_msg_queue_proc():
-    logger.info(datetime.now())
-    db = get_db_local()
-    rows = db.query(YzyMsgQueue).filter(YzyMsgQueue.sent_status == 0).limit(20).all()
-    for row in rows:
-        try:
-            resp = YzyApi.send_textcard_message(row.yzy_userid, row.title, row.content, row.detail_url)
-            logger.info(resp)
-            row.sent_time = datetime.now()
-            if resp['errcode'] == 0:
-                row.sent_status = 1
-                row.errmsg = resp['jobid']
-            else:
-                row.sent_status = 9
-                row.errmsg = resp['errmsg']
-            db.commit()
-        except Exception as e:
-            traceback.print_exec()
-        
-    db.close()
+    lock_key = "yzy_job_proc"
+    if redis_lock(lock_key):
+        logger.info(datetime.now())
+        db = get_db_local()
+        rows = db.query(YzyMsgQueue).filter(YzyMsgQueue.sent_status == 0).limit(20).all()
+        for row in rows:
+            try:
+                resp = YzyApi.send_textcard_message(row.yzy_userid, row.title, row.content, row.detail_url)
+                logger.info(resp)
+                row.sent_time = datetime.now()
+                if resp['errcode'] == 0:
+                    row.sent_status = 1
+                    row.errmsg = resp['jobid']
+                else:
+                    row.sent_status = 9
+                    row.errmsg = resp['errmsg']
+                db.commit()
+            except Exception as e:
+                traceback.print_exec()
+            
+        db.close()
+
+        redis_unlock(lock_key)