Skip to content

Commit

Permalink
explore args
Browse files Browse the repository at this point in the history
  • Loading branch information
jonavellecuerdo committed Jan 13, 2025
1 parent a24639a commit a2e06cf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
13 changes: 7 additions & 6 deletions dsc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
help="The handle of the DSpace collection to which the batch will be submitted",
required=True,
)
@click.option(
"-e",
"--email-recipients",
help="The recipients of the submission results email",
required=True,
)
@click.option(
"-b",
"--batch-id",
Expand All @@ -42,11 +48,6 @@
"--output-queue",
help="The SQS output queue for the DSS result messages",
)
@click.option(
"-e",
"--email-recipients",
help="The recipients of the submission results email",
)
@click.option(
"-v", "--verbose", is_flag=True, help="Pass to log at debug level instead of info"
)
Expand All @@ -55,9 +56,9 @@ def main(
workflow_name: str,
collection_handle: str,
batch_id: str,
email_recipients: tuple[str],
s3_bucket: str | None,
output_queue: str | None,
email_recipients: tuple[str] | None,
verbose: bool, # noqa: FBT001
) -> None:
ctx.ensure_object(dict)
Expand Down
38 changes: 24 additions & 14 deletions dsc/workflows/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ class Workflow(ABC):
workflow_name: str = "base"
submission_system: str = "DSpace@MIT"
metadata_mapping_path: str = ""
output_queue = "dsc-unhandled"

def __init__(
self,
collection_handle: str,
batch_id: str,
email_recipients: tuple[str] = ("None",),
s3_bucket: str = "dsc",
output_queue: str = "dsc-unhandled",
email_recipients: tuple[str],
s3_bucket: str | None,
output_queue: str | None,
) -> None:
"""Initialize base instance.
Expand All @@ -54,8 +55,11 @@ def __init__(
self.collection_handle = collection_handle
self.batch_id = batch_id
self.email_recipients = email_recipients
self.s3_bucket = s3_bucket
self.output_queue = output_queue

if s3_bucket is not None:
self.s3_bucket = s3_bucket
if output_queue is not None:
self.output_queue = output_queue

@property
def batch_path(self) -> str:
Expand All @@ -68,25 +72,31 @@ def metadata_mapping(self) -> dict:

@final
@classmethod
def load(
def load( # noqa: D417
cls,
workflow_name: str,
**kwargs: str | tuple | None,
collection_handle: str,
batch_id: str,
email_recipients: tuple[str],
s3_bucket: str | None = None,
output_queue: str | None = None,
) -> Workflow:
"""Return configured workflow class instance.
Args:
workflow_name: The label of the workflow. Must match a key from
config.WORKFLOWS.
**kwargs: Includes required arguments (collection_handle, batch_id,
email_recipients) as well as optional arguments (s3_bucket, output_queue)
that override the class's default values.
See Workflow.__init__ for args.
"""
workflow_class = cls.get_workflow(workflow_name)
filtered_kwargs = {
key: value for key, value in kwargs.items() if value is not None
}
return workflow_class(**filtered_kwargs) # type: ignore [arg-type]
return workflow_class(
collection_handle=collection_handle,
batch_id=batch_id,
email_recipients=email_recipients,
s3_bucket=s3_bucket,
output_queue=output_queue,
)

@final
@classmethod
Expand Down

0 comments on commit a2e06cf

Please sign in to comment.