-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 上云周期任务添加最低任务间隔时间配置 --story=120737215 #7619
feat: 上云周期任务添加最低任务间隔时间配置 --story=120737215 #7619
Conversation
--bug=129170523 # Reviewed, transaction id: 23091
# Reviewed, transaction id: 23746
# Reviewed, transaction id: 24302
@@ -234,6 +237,19 @@ def test_delete(self): | |||
PipelinePeriodicTask.DoesNotExist, PipelinePeriodicTask.objects.get, id=pipeline_periodic_task_id | |||
) | |||
|
|||
def test_inspect_time(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测试样例:
- 全是 *
- 没有超过时间限制的
- 前面 n 次内有超过时间的
- 前面 n 次没有超过时间限制,但是 n 次之后超过的
…nto edit_time_interval
env.py
Outdated
# 周期任务最短时间间隔,以分钟为单位,例如:30 | ||
PERIODIC_TASK_SHORTEST_TIME = os.getenv("PERIODIC_TASK_SHORTEST_TIME", "") | ||
# 周期任务迭代次数 | ||
PERIODIC_TASK_ITERATION = os.getenv("PERIODIC_TASK_ITERATION", 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int()
item_num=int(settings.PERIODIC_TASK_ITERATION), | ||
) | ||
if not result: | ||
raise ValidationException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里理论上用 serializer 校验失败的 exception
return attrs | ||
|
||
def inspect_time(self, request, cron): | ||
if settings.PERIODIC_TASK_SHORTEST_TIME: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not settings.PERIODIC_TASK_SHORTEST_TIME:
return
env.py
Outdated
@@ -150,6 +150,11 @@ | |||
# 周期任务消息通知类型 | |||
PERIODIC_TASK_REMINDER_NOTIFY_TYPE = json.loads(os.getenv("PERIODIC_TASK_REMINDER_NOTIFY_TYPE", '["email"]')) | |||
|
|||
# 周期任务最短时间间隔,以分钟为单位,例如:30 | |||
PERIODIC_TASK_SHORTEST_TIME = os.getenv("PERIODIC_TASK_SHORTEST_TIME", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果是 30,是否用 int 比较合理,默认 0 代表没有限制
gcloud/periodictask/models.py
Outdated
@@ -254,6 +256,38 @@ def delete(self, using=None): | |||
super(PeriodicTask, self).delete(using) | |||
PeriodicTaskHistory.objects.filter(task=self).delete() | |||
|
|||
def inspect_time(self, is_superuser, cron, shortest_time, item_num): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是不是不用写在 model
gcloud/periodictask/models.py
Outdated
|
||
schedule_iter = croniter(cron_expression) | ||
# 计算指定次数内的最短时间间隔 | ||
next_times = [schedule_iter.get_next(datetime) for _ in range(item_num)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果是后面只会执行一次或两次的,item_num 过大会不会有问题,补充下单测
No description provided.