-
Notifications
You must be signed in to change notification settings - Fork 632
Feature: Scheduler pipeline management: Pause/Resume #30
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
| from pipeline.models import Pipeline | ||
| from rest_framework import serializers | ||
|
|
||
|
|
||
| class PipelineUpdateSerializer(serializers.Serializer): | ||
| pipeline_id = serializers.UUIDField(required=True) | ||
| active = serializers.BooleanField(required=True) | ||
|
|
||
| def validate_pipeline_id(self, value: str) -> str: | ||
| try: | ||
| Pipeline.objects.get(pk=value) | ||
| except Pipeline.DoesNotExist: | ||
| raise serializers.ValidationError("Invalid pipeline ID") | ||
| return value |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,15 +2,15 @@ | |
| import logging | ||
| from typing import Any, Optional | ||
|
|
||
| from pipeline.models import Pipeline | ||
| from account.models import Organization | ||
| from celery import shared_task | ||
| from django_celery_beat.models import CrontabSchedule, PeriodicTask | ||
| from django_tenants.utils import get_tenant_model, tenant_context | ||
| from pipeline.models import Pipeline | ||
| from pipeline.pipeline_processor import PipelineProcessor | ||
| from pymysql import IntegrityError | ||
| from workflow_manager.workflow.models.workflow import Workflow | ||
| from workflow_manager.workflow.workflow_helper import WorkflowHelper | ||
| from pipeline.pipeline_processor import PipelineProcessor | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -59,14 +59,19 @@ def create_periodic_task( | |
|
|
||
|
|
||
| def update_pipeline( | ||
| pipeline_guid: Optional[str], status: tuple[str, str] | ||
| pipeline_guid: Optional[str], | ||
| status: tuple[str, str], | ||
| is_active: Optional[bool] = None, | ||
| ) -> Any: | ||
| if pipeline_guid: | ||
| check_active = True | ||
| if is_active is True: | ||
| check_active = False | ||
| pipeline: Pipeline = PipelineProcessor.fetch_pipeline( | ||
| pipeline_id=pipeline_guid | ||
| pipeline_id=pipeline_guid, check_active=check_active | ||
| ) | ||
| PipelineProcessor.update_pipeline_status( | ||
| pipeline=pipeline, is_end=True, status=status | ||
| pipeline=pipeline, is_end=True, status=status, is_active=is_active | ||
| ) | ||
| logger.info(f"Updated pipeline status: {status}") | ||
|
|
||
|
|
@@ -120,3 +125,19 @@ def delete_periodic_task(task_name: str) -> None: | |
| logger.error(f"Periodic task does not exist: {task_name}") | ||
| except Exception as e: | ||
| logger.error(f"Failed to delete periodic task: {e}") | ||
|
|
||
|
|
||
| @shared_task | ||
| def disable_task(task_name: str) -> None: | ||
| task = PeriodicTask.objects.get(name=task_name) | ||
| task.enabled = False | ||
| task.save() | ||
| update_pipeline(task_name, Pipeline.PipelineStatus.PAUSED, False) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: @athul-rs using named kwargs is much more explicit when passing around bools - in this case we'll have to inspect the function to know the behaviour |
||
|
|
||
|
|
||
| @shared_task | ||
| def enable_task(task_name: str) -> None: | ||
| task = PeriodicTask.objects.get(name=task_name) | ||
| task.enabled = True | ||
| task.save() | ||
| update_pipeline(task_name, Pipeline.PipelineStatus.RESTARTING, True) | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.