Skip to content

Commit 614cfcc

Browse files
committed
Track execution timeout in schedule model
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 263f503 commit 614cfcc

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

vulnerabilities/migrations/0092_pipelineschedule_pipelinerun.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 4.2.20 on 2025-05-12 17:04
1+
# Generated by Django 4.2.20 on 2025-05-21 19:32
22

33
import django.core.validators
44
from django.db import migrations, models
@@ -65,6 +65,21 @@ class Migration(migrations.Migration):
6565
unique=True,
6666
),
6767
),
68+
(
69+
"execution_timeout",
70+
models.PositiveSmallIntegerField(
71+
default=24,
72+
help_text="Number hours before pipeline execution is forcefully terminated.",
73+
validators=[
74+
django.core.validators.MinValueValidator(
75+
1, message="Pipeline timeout must be at least 1 hour."
76+
),
77+
django.core.validators.MaxValueValidator(
78+
72, message="Pipeline timeout must be at most 72 hours."
79+
),
80+
],
81+
),
82+
),
6883
("created_date", models.DateTimeField(auto_now_add=True, db_index=True)),
6984
],
7085
options={

vulnerabilities/models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import django_rq
2323
import redis
24-
from aboutcode.pipeline import humanize_time
2524
from cvss.exceptions import CVSS2MalformedError
2625
from cvss.exceptions import CVSS3MalformedError
2726
from cvss.exceptions import CVSS4MalformedError
@@ -65,6 +64,7 @@
6564
from vulnerabilities.utils import normalize_purl
6665
from vulnerabilities.utils import purl_to_dict
6766
from vulnerablecode import __version__ as VULNERABLECODE_VERSION
67+
from vulnerablecode.settings import VULNERABLECODE_PIPELINE_TIMEOUT
6868

6969
logger = logging.getLogger(__name__)
7070

@@ -2147,6 +2147,15 @@ class PipelineSchedule(models.Model):
21472147
help_text=("Identifier used to manage the periodic run job."),
21482148
)
21492149

2150+
execution_timeout = models.PositiveSmallIntegerField(
2151+
validators=[
2152+
MinValueValidator(1, message="Pipeline timeout must be at least 1 hour."),
2153+
MaxValueValidator(72, message="Pipeline timeout must be at most 72 hours."),
2154+
],
2155+
default=VULNERABLECODE_PIPELINE_TIMEOUT,
2156+
help_text=("Number hours before pipeline execution is forcefully terminated."),
2157+
)
2158+
21502159
created_date = models.DateTimeField(
21512160
auto_now_add=True,
21522161
db_index=True,

vulnerabilities/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def enqueue_pipeline(pipeline_id):
115115
run.run_id,
116116
job_id=str(run.run_id),
117117
on_failure=set_run_failure,
118-
job_timeout=VULNERABLECODE_PIPELINE_TIMEOUT,
118+
job_timeout=f"{pipeline_schedule.execution_timeout}h",
119119
)
120120

121121

vulnerablecode/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@
366366
}
367367

368368

369-
VULNERABLECODE_ASYNC = True
370-
VULNERABLECODE_PIPELINE_TIMEOUT = "24h"
369+
VULNERABLECODE_PIPELINE_TIMEOUT = env.int("VULNERABLECODE_PIPELINE_TIMEOUT", default=24)
371370
RQ_QUEUES = {
372371
"default": {
373372
"HOST": env.str("VULNERABLECODE_REDIS_HOST", default="localhost"),

0 commit comments

Comments
 (0)