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: conditionally run pipelines in debug mode #862

Merged
1 change: 1 addition & 0 deletions hexa/pipelines/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ input RunPipelineInput {
versionId: UUID # The ID of the pipeline version to use for the run.
config: JSON! # The configuration for the pipeline run.
sendMailNotifications: Boolean # Indicates if email notifications should be sent for the pipeline run.
enableDebugLogs: Boolean # Indicates if debug logs should be stored for the pipeline run.
}

"""
Expand Down
1 change: 1 addition & 0 deletions hexa/pipelines/management/commands/pipelines_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def run_pipeline(run: PipelineRun):
"HEXA_RUN_ID": str(run.id),
"HEXA_PIPELINE_NAME": run.pipeline.name,
"HEXA_PIPELINE_TYPE": run.pipeline.type,
"HEXA_LOG_LEVEL": run.log_level,
}
if run.pipeline.type == PipelineType.NOTEBOOK:
env_vars.update({"HEXA_NOTEBOOK_PATH": run.pipeline.notebook_path})
Expand Down
26 changes: 26 additions & 0 deletions hexa/pipelines/migrations/0053_pipelinerun_log_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.16 on 2024-12-02 13:12

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("pipelines", "0052_pipelineversion_version_number_revert_logic"),
]

operations = [
migrations.AddField(
model_name="pipelinerun",
name="log_level",
field=models.IntegerField(
choices=[
(0, "Debug"),
(1, "Info"),
(2, "Warning"),
(3, "Error"),
(4, "Critical"),
],
default=1,
),
),
]
14 changes: 13 additions & 1 deletion hexa/pipelines/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ class PipelineType(models.TextChoices):
ZIPFILE = "zipFile", _("ZipFile")


class PipelineRunLogLevel(models.IntegerChoices):
DEBUG = 0
INFO = 1
WARNING = 2
ERROR = 3
CRITICAL = 4


class Pipeline(SoftDeletedModel):
class Meta:
verbose_name = "Pipeline"
Expand Down Expand Up @@ -283,6 +291,7 @@ def run(
trigger_mode: PipelineRunTrigger,
config: typing.Mapping[typing.Dict, typing.Any] | None = None,
send_mail_notifications: bool = True,
log_level: PipelineRunLogLevel = PipelineRunLogLevel.INFO,
):
timeout = settings.PIPELINE_RUN_DEFAULT_TIMEOUT
if pipeline_version and pipeline_version.timeout:
Expand All @@ -303,6 +312,7 @@ def run(
access_token=str(uuid.uuid4()),
send_mail_notifications=send_mail_notifications,
timeout=timeout,
log_level=log_level,
)

return run
Expand Down Expand Up @@ -557,7 +567,9 @@ class Meta:
on_delete=models.SET_NULL,
related_name="+",
)

log_level = models.IntegerField(
choices=PipelineRunLogLevel.choices, default=PipelineRunLogLevel.INFO
)
objects = PipelineRunQuerySet.as_manager()

@property
Expand Down
4 changes: 4 additions & 0 deletions hexa/pipelines/schema/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
PipelineDoesNotSupportParametersError,
PipelineRecipient,
PipelineRun,
PipelineRunLogLevel,
PipelineRunState,
PipelineRunTrigger,
PipelineType,
Expand Down Expand Up @@ -215,6 +216,9 @@ def resolve_run_pipeline(_, info, **kwargs):
trigger_mode=PipelineRunTrigger.MANUAL,
config=input.get("config", {}),
send_mail_notifications=input.get("sendMailNotifications", False),
log_level=PipelineRunLogLevel.DEBUG
if input.get("enableDebugLogs", False)
else PipelineRunLogLevel.INFO,
)
track(
request,
Expand Down
Loading