-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: conditionally run pipelines in debug mode (#862)
* Add log level to model + wire it in env * Remove todo * Merge * Fix * Fix * Wire backend * Wire backend * Wire backend * Fix wiring * Add tests * Working test * Simplify test * Simplify test * Add to view * Add safe parsing and tests * Cleaner tests
- Loading branch information
Showing
10 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from unittest.mock import MagicMock, patch | ||
|
||
from django.test import TestCase, override_settings | ||
|
||
from hexa.pipelines.management.commands.pipelines_runner import run_pipeline | ||
from hexa.pipelines.models import PipelineRun, PipelineRunLogLevel, PipelineType | ||
|
||
|
||
class TestRunPipeline(TestCase): | ||
@override_settings( | ||
INTERNAL_BASE_URL="http://testserver", | ||
DEFAULT_WORKSPACE_IMAGE="default_workspace_image", | ||
PIPELINE_SCHEDULER_SPAWNER="docker", | ||
) | ||
@patch("hexa.pipelines.management.commands.pipelines_runner.run_pipeline_docker") | ||
@patch("os.fork", return_value=0) | ||
def test_env_vars(self, _, mock_run_pipeline_docker): | ||
mock_run = MagicMock(spec=PipelineRun) | ||
mock_run.id = 123 | ||
mock_run.access_token = "someAccessToken" | ||
mock_run.log_level = PipelineRunLogLevel.DEBUG | ||
mock_run.pipeline.workspace.slug = "test_workspace" | ||
mock_run.pipeline.workspace.docker_image = "docker_image" | ||
mock_run.pipeline.name = "test_pipeline" | ||
mock_run.pipeline.type = PipelineType.NOTEBOOK | ||
mock_run.pipeline.notebook_path = "/path/to/notebook" | ||
mock_run.pipeline.code = "pipeline_code" | ||
mock_run.send_mail_notifications = False | ||
|
||
mock_run_pipeline_docker.return_value = (True, "SomeLogs") | ||
|
||
with self.assertRaises(SystemExit): | ||
run_pipeline(mock_run) | ||
|
||
expected_env_vars = { | ||
"HEXA_SERVER_URL": "http://testserver", | ||
"HEXA_TOKEN": "InNvbWVBY2Nlc3NUb2tlbiI:6jqo7CX79O6IOh7lgqpwOXBBYSxzNOBtXeSNb4ry9EM", | ||
"HEXA_WORKSPACE": "test_workspace", | ||
"HEXA_RUN_ID": "123", | ||
"HEXA_PIPELINE_NAME": "test_pipeline", | ||
"HEXA_PIPELINE_TYPE": PipelineType.NOTEBOOK, | ||
"HEXA_LOG_LEVEL": PipelineRunLogLevel.DEBUG, | ||
"HEXA_NOTEBOOK_PATH": "/path/to/notebook", | ||
} | ||
mock_run_pipeline_docker.assert_called_once_with( | ||
mock_run, "docker_image", expected_env_vars | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters