Skip to content

Commit

Permalink
feat: Add an 'operation' argument to the job bundle export callback.
Browse files Browse the repository at this point in the history
Signed-off-by: Ramon Montoya Vozmediano <1171039+rmv@users.noreply.github.com>
  • Loading branch information
rmv committed Oct 26, 2023
1 parent a450090 commit 9a059d4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 30 deletions.
4 changes: 4 additions & 0 deletions src/deadline/client/ui/dialogs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

from ._types import (
CallbackOperation, # noqa: F401
)

__all__ = ["DeadlineConfigDialog", "DeadlineLoginDialog"]

from .deadline_config_dialog import DeadlineConfigDialog
Expand Down
13 changes: 13 additions & 0 deletions src/deadline/client/ui/dialogs/_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

from enum import Enum

# ---- Types to export


class CallbackOperation(str, Enum):
EXPORT = "export"
"""A job bundle is being created for export."""

SUBMISSION = "submission"
"""A job bundle is being created for immediation submission."""
93 changes: 63 additions & 30 deletions src/deadline/client/ui/dialogs/submit_job_to_deadline_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from ..widgets.host_requirements_tab import HostRequirementsWidget
from . import DeadlineConfigDialog, DeadlineLoginDialog
from ...job_bundle.submission import AssetReferences
from ._types import CallbackOperation

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -322,6 +323,54 @@ def on_settings_button_clicked(self):
if DeadlineConfigDialog.configure_settings(parent=self):
self.refresh_deadline_settings()

def _on_create_job_bundle_callback(
self,
job_history_bundle_dir: str,
settings: QWidget,
queue_parameters: list[dict[str, Any]],
asset_references: AssetReferences,
operation: CallbackOperation,
) -> None:
"""
Calls the provided callback ensuring backwards compatibility
"""
if self.show_host_requirements_tab:
requirements = self.host_requirements.get_requirements()
try:
self.on_create_job_bundle_callback(
self,
job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
requirements,
operation,
)
except TypeError:
self.on_create_job_bundle_callback(
self,
job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
requirements,
)
else:
# Maintaining backward compatibility for submitters that do not support host_requirements yet
try:
self.on_create_job_bundle_callback(
self,
job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
operation,
)
except TypeError:
self.on_create_job_bundle_callback(
self, job_history_bundle_dir, settings, queue_parameters, asset_references
)

def on_export_bundle(self):
"""
Exports a Job Bundle, but does not submit the job.
Expand All @@ -341,21 +390,13 @@ def on_export_bundle(self):
settings.submitter_name, settings.name
)

if self.show_host_requirements_tab:
requirements = self.host_requirements.get_requirements()
self.on_create_job_bundle_callback(
self,
job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
requirements,
)
else:
# Maintaining backward compatibility for submitters that do not support host_requirements yet
self.on_create_job_bundle_callback(
self, job_history_bundle_dir, settings, queue_parameters, asset_references
)
self._on_create_job_bundle_callback(
job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
CallbackOperation.EXPORT,
)

logger.info(f"Saved the submission as a job bundle: {job_history_bundle_dir}")
if sys.platform == "win32":
Expand Down Expand Up @@ -398,21 +439,13 @@ def on_submit(self):
settings.submitter_name, settings.name
)

if self.show_host_requirements_tab:
requirements = self.host_requirements.get_requirements()
self.on_create_job_bundle_callback(
self,
job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
requirements,
)
else:
# Maintaining backward compatibility for submitters that do not support host_requirements yet
self.on_create_job_bundle_callback(
self, job_history_bundle_dir, settings, queue_parameters, asset_references
)
self._on_create_job_bundle_callback(
job_history_bundle_dir,
settings,
queue_parameters,
asset_references,
CallbackOperation.SUBMISSION,
)

farm_id = get_setting("defaults.farm_id")
queue_id = get_setting("defaults.queue_id")
Expand Down

0 comments on commit 9a059d4

Please sign in to comment.