Skip to content

Commit 970dadd

Browse files
committed
feat: add migration to increase pipeline run frequency
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 9874639 commit 970dadd

4 files changed

Lines changed: 57 additions & 6 deletions

File tree

‎vulnerabilities/api_v2.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ def get_latest_run(self, schedule):
788788

789789
def to_representation(self, schedule):
790790
representation = super().to_representation(schedule)
791-
representation["run_interval"] = f"{schedule.run_interval}hr"
791+
representation["run_interval"] = f"{schedule.run_interval}min"
792792
representation["execution_timeout"] = f"{schedule.execution_timeout}hr"
793793
return representation
794794

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Generated by Django 5.2.11 on 2026-06-15 11:50
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
from django.db.models import F
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("vulnerabilities", "0135_advisoryexploit_record_id_and_more"),
11+
]
12+
13+
def convert_hours_to_minutes(apps, schema_editor):
14+
PipelineSchedule = apps.get_model("vulnerabilities", "PipelineSchedule")
15+
PipelineSchedule.objects.update(
16+
run_interval=F("run_interval") * 60
17+
)
18+
19+
def revert_convert_hours_to_minutes(apps, schema_editor):
20+
PipelineSchedule = apps.get_model("vulnerabilities", "PipelineSchedule")
21+
for schedule in PipelineSchedule.objects.all():
22+
schedule.run_interval = min(
23+
8760,
24+
max(1, schedule.run_interval // 60)
25+
)
26+
schedule.save(update_fields=["run_interval"])
27+
28+
operations = [
29+
migrations.AlterField(
30+
model_name="pipelineschedule",
31+
name="run_interval",
32+
field=models.PositiveSmallIntegerField(
33+
default=1440,
34+
help_text="Number of minutes to wait between run of this pipeline.",
35+
validators=[
36+
django.core.validators.MinValueValidator(
37+
5, message="Interval must be at least 5 minutes."
38+
),
39+
django.core.validators.MaxValueValidator(
40+
43200, message="Interval must be at most 43200 minutes (i.e 30 days)."
41+
),
42+
],
43+
),
44+
),
45+
migrations.RunPython(
46+
convert_hours_to_minutes,
47+
revert_convert_hours_to_minutes,
48+
),
49+
]

‎vulnerabilities/models.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,11 +2304,13 @@ class ExecutionPriority(models.IntegerChoices):
23042304

23052305
run_interval = models.PositiveSmallIntegerField(
23062306
validators=[
2307-
MinValueValidator(1, message="Interval must be at least 1 hour."),
2308-
MaxValueValidator(8760, message="Interval must be at most 8760 hours."),
2307+
MinValueValidator(5, message="Interval must be at least 5 minutes."),
2308+
MaxValueValidator(
2309+
43200, message="Interval must be at most 43200 minutes (i.e 30 days)."
2310+
),
23092311
],
2310-
default=24,
2311-
help_text=("Number of hours to wait between run of this pipeline."),
2312+
default=1440,
2313+
help_text=("Number of minutes to wait between run of this pipeline."),
23122314
)
23132315

23142316
run_priority = models.IntegerField(

‎vulnerabilities/tasks.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def compute_queue_load_factor():
179179

180180
for queue in RQ_QUEUES.keys():
181181
total_compute_seconds_per_queue[queue] = sum(
182-
(p.latest_successful_run.runtime / (p.run_interval / 24))
182+
(p.latest_successful_run.runtime / (p.run_interval / (24 * 60)))
183183
for p in models.PipelineSchedule.objects.filter(
184184
is_active=True, run_priority=label_to_value[queue]
185185
)

0 commit comments

Comments
 (0)