Skip to content

Commit

Permalink
fix: 修改发送周期任务消息周期时间 TencentBlueKing#7364
Browse files Browse the repository at this point in the history
  • Loading branch information
lTimej committed Apr 17, 2024
1 parent aa0de01 commit c9f213c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,9 @@ def check_engine_admin_permission(request, *args, **kwargs):
# 周期任务自动关闭扫描频率
PERIODIC_TASK_REMINDER_TIME = env.PERIODIC_TASK_REMINDER_TIME

# 发送周期任务消息通知开关(默认关)
PERIODIC_TASK_REMINDER_SWITCH = env.PERIODIC_TASK_REMINDER_SWITCH

# 周期任务自动关闭扫描周期
PERIODIC_TASK_REMINDER_SCAN_CRON = env.PERIODIC_TASK_REMINDER_SCAN_CRON

Expand Down
5 changes: 4 additions & 1 deletion env.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@
# 周期任务自动关闭扫描频率(单位:月)
PERIODIC_TASK_REMINDER_TIME = int(os.getenv("BKAPP_PERIODIC_TASK_REMINDER_TIME", 1))

# 发送周期任务消息通知开关
PERIODIC_TASK_REMINDER_SWITCH = int(os.getenv("BKAPP_PERIODIC_TASK_REMINDER_SWITCH", 0))

# 周期任务自动关闭扫描周期
PERIODIC_TASK_REMINDER_SCAN_CRON = json.loads(
os.getenv("BKAPP_PERIODIC_TASK_REMINDER_SCAN_CRON", '{"hour": "23", "minute": "0"}')
os.getenv("BKAPP_PERIODIC_TASK_REMINDER_SCAN_CRON", '{"hour": "10", "minute": "20"}')
)

# 周期任务消息通知类型
Expand Down
4 changes: 3 additions & 1 deletion gcloud/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def send_periodic_task_notify(executor, notify_type, receivers, title, content):

@periodic_task(run_every=TzAwareCrontab(**settings.PERIODIC_TASK_REMINDER_SCAN_CRON))
def scan_periodic_task(is_send_notify: bool = True):
if not settings.PERIODIC_TASK_REMINDER_SWITCH:
return
title = "【标准运维 APP 提醒】请确认您正在运行的周期任务状态"
# 以执行人维度发邮件通知
periodic_tasks = (
Expand Down Expand Up @@ -216,7 +218,7 @@ def scan_periodic_task(is_send_notify: bool = True):
},
)
send_periodic_task_notify.delay(
"admin", settings.PERIODIC_TASK_REMINDER_NOTIFY_TYPE, "liujun", title, mail_content
"admin", settings.PERIODIC_TASK_REMINDER_NOTIFY_TYPE, notifier, title, mail_content
)
except Exception as e:
logger.exception(f"send periodic task notify error: {e}")
Expand Down

0 comments on commit c9f213c

Please sign in to comment.