Skip to content

Commit 7a663dc

Browse files
committed
Keep run interval in hours
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 5da9a77 commit 7a663dc

File tree

4 files changed

+79
-6
lines changed

4 files changed

+79
-6
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Generated by Django 4.2.22 on 2025-06-24 16:33
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
from datetime import datetime
6+
from datetime import timezone
7+
8+
from aboutcode.pipeline import LoopProgress
9+
10+
class Migration(migrations.Migration):
11+
def update_old_interval(apps, schema_editor):
12+
Pipeline = apps.get_model("vulnerabilities", "PipelineSchedule")
13+
pipeline_schedule = Pipeline.objects.all()
14+
15+
log(f"\nUpdating interval for {pipeline_schedule.count():,d} pipeline")
16+
progress = LoopProgress(
17+
total_iterations=pipeline_schedule.count(),
18+
progress_step=10,
19+
logger=log,
20+
)
21+
for pipeline in progress.iter(pipeline_schedule.iterator()):
22+
pipeline.run_interval = pipeline.run_interval * 24
23+
pipeline.save()
24+
25+
def reverse_update_old_interval(apps, schema_editor):
26+
Pipeline = apps.get_model("vulnerabilities", "PipelineSchedule")
27+
pipeline_schedule = Pipeline.objects.all()
28+
29+
log(f"\nReverse interval for {pipeline_schedule.count():,d} pipeline")
30+
progress = LoopProgress(
31+
total_iterations=pipeline_schedule.count(),
32+
progress_step=10,
33+
logger=log,
34+
)
35+
for pipeline in progress.iter(pipeline_schedule.iterator()):
36+
pipeline.run_interval = pipeline.run_interval / 24
37+
pipeline.save()
38+
39+
dependencies = [
40+
("vulnerabilities", "0092_pipelineschedule_pipelinerun"),
41+
]
42+
43+
operations = [
44+
migrations.AlterField(
45+
model_name="pipelineschedule",
46+
name="run_interval",
47+
field=models.PositiveSmallIntegerField(
48+
default=24,
49+
help_text="Number of hours to wait between run of this pipeline.",
50+
validators=[
51+
django.core.validators.MinValueValidator(
52+
1, message="Interval must be at least 1 hour."
53+
),
54+
django.core.validators.MaxValueValidator(
55+
8760, message="Interval must be at most 8760 hours."
56+
),
57+
],
58+
),
59+
),
60+
migrations.RunPython(
61+
code=update_old_interval,
62+
reverse_code=reverse_update_old_interval,
63+
),
64+
]
65+
66+
67+
def log(message):
68+
now_local = datetime.now(timezone.utc).astimezone()
69+
timestamp = now_local.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
70+
message = f"{timestamp} {message}"
71+
print(message)

vulnerabilities/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,11 +2141,11 @@ class PipelineSchedule(models.Model):
21412141

21422142
run_interval = models.PositiveSmallIntegerField(
21432143
validators=[
2144-
MinValueValidator(1, message="Interval must be at least 1 day."),
2145-
MaxValueValidator(365, message="Interval must be at most 365 days."),
2144+
MinValueValidator(1, message="Interval must be at least 1 hour."),
2145+
MaxValueValidator(8760, message="Interval must be at most 8760 hours."),
21462146
],
2147-
default=1,
2148-
help_text=("Number of days to wait between run of this pipeline."),
2147+
default=24,
2148+
help_text=("Number of hours to wait between run of this pipeline."),
21492149
)
21502150

21512151
schedule_work_id = models.CharField(

vulnerabilities/schedules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def schedule_execution(pipeline_schedule, execute_now=False):
2828
if not execute_now:
2929
first_execution = pipeline_schedule.next_run_date
3030

31-
interval_in_seconds = pipeline_schedule.run_interval * 24 * 60 * 60
31+
interval_in_seconds = pipeline_schedule.run_interval * 60 * 60
3232

3333
job = scheduler.schedule(
3434
scheduled_time=first_execution,

vulnerabilities/templates/pipeline_dashboard.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ <h1>Pipeline Dashboard</h1>
7272
<div class="columns px-1 is-mobile is-vcentered">
7373
<div class="column is-one-quarter">{{ schedule.pipeline_id }}</div>
7474
<div class="column is-one-eighth has-text-grey">{{ schedule.is_active|yesno:"Yes,No" }}</div>
75-
<div class="column is-one-eighth has-text-grey">{{ schedule.run_interval }}day</div>
75+
<div class="column is-one-eighth has-text-grey">
76+
{{ schedule.run_interval }} hour{{ schedule.run_interval|pluralize }}
77+
</div>
7678
<div class="column is-one-eighth">
7779
<span class="is-flex is-align-items-center">
7880
{% include "includes/job_status.html" with status=schedule.status %}

0 commit comments

Comments
 (0)