Skip to content
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

Conversation

guohelu
Copy link
Collaborator

@guohelu guohelu commented Nov 21, 2024

No description provided.

env.py Outdated Show resolved Hide resolved
gcloud/periodictask/models.py Outdated Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
gcloud/periodictask/models.py Outdated Show resolved Hide resolved
gcloud/core/apis/drf/viewsets/periodic_task.py Outdated Show resolved Hide resolved
gcloud/periodictask/models.py Outdated Show resolved Hide resolved
gcloud/periodictask/models.py Outdated Show resolved Hide resolved
gcloud/periodictask/models.py Outdated Show resolved Hide resolved
gcloud/periodictask/models.py Outdated Show resolved Hide resolved
@@ -234,6 +237,19 @@ def test_delete(self):
PipelinePeriodicTask.DoesNotExist, PipelinePeriodicTask.objects.get, id=pipeline_periodic_task_id
)

def test_inspect_time(self):
Copy link
Member

@normal-wls normal-wls Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试样例:

  1. 全是 *
  2. 没有超过时间限制的
  3. 前面 n 次内有超过时间的
  4. 前面 n 次没有超过时间限制,但是 n 次之后超过的

env.py Outdated
# 周期任务最短时间间隔,以分钟为单位,例如:30
PERIODIC_TASK_SHORTEST_TIME = os.getenv("PERIODIC_TASK_SHORTEST_TIME", "")
# 周期任务迭代次数
PERIODIC_TASK_ITERATION = os.getenv("PERIODIC_TASK_ITERATION", 10)
Copy link
Member

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(
Copy link
Member

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:
Copy link
Member

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", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是 30,是否用 int 比较合理,默认 0 代表没有限制

@@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是不是不用写在 model


schedule_iter = croniter(cron_expression)
# 计算指定次数内的最短时间间隔
next_times = [schedule_iter.get_next(datetime) for _ in range(item_num)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是后面只会执行一次或两次的,item_num 过大会不会有问题,补充下单测

@guohelu guohelu closed this Nov 26, 2024
@guohelu guohelu deleted the edit_time_interval branch December 17, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants