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

Added workflows execute-all <workflowId> <datasetId> #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 13.3.0 - 2024-06-27

- Added `workflows execute-all` which starts an execution on all documents in a dataset

## Version 13.2.2 - 2024-06-13

- Bugfix `models update-training` now works as intended when specifying `--deployment-environment-id`
Expand Down
2 changes: 1 addition & 1 deletion lascli/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
__maintainer_email__ = 'magnus@lucidtech.ai'
__title__ = 'lucidtech-las-cli'
__url__ = 'https://github.com/LucidtechAI/las-cli'
__version__ = '13.2.2'
__version__ = '13.3.0'
27 changes: 27 additions & 0 deletions lascli/parser/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pathlib
import textwrap
from argparse import RawTextHelpFormatter
from functools import partial

import dateparser
from las import Client
Expand Down Expand Up @@ -32,6 +33,27 @@ def execute_workflow(las_client: Client, workflow_id, path):
return las_client.execute_workflow(workflow_id, content)


def execute_all_workflow(las_client: Client, workflow_id, dataset_id):
list_fn = partial(las_client.list_documents, dataset_id=dataset_id)
list_response = list_fn()
documents = list_response['documents']
while next_token := list_response['nextToken']:
list_response = list_fn(next_token=next_token)
documents.extend(list_response['documents'])
augustak marked this conversation as resolved.
Show resolved Hide resolved

executions = []
for i, document in enumerate(documents):
content = {'documentId': document['documentId'], 'source': 'CLI', 'initialSleepInSeconds': i * 4}
if originalFilePath := document.get('metadata', {}).get('originalFilePath'):
augustak marked this conversation as resolved.
Show resolved Hide resolved
file_path = pathlib.Path(originalFilePath)
content['title'] = file_path.name
execution = las_client.execute_workflow(workflow_id, content)
print(json.dumps(execution, indent=2))
executions.append(execution)

return f'Started {len(executions)} executions'


def list_workflow_executions(las_client: Client, workflow_id, **optional_args):
return las_client.list_workflow_executions(workflow_id, **optional_args)

Expand Down Expand Up @@ -196,6 +218,11 @@ def create_workflows_parser(subparsers):
execute_workflow_parser.add_argument('path', help='path to json-file with input to the first state of the workflow')
execute_workflow_parser.set_defaults(cmd=execute_workflow)

execute_workflow_parser = subparsers.add_parser('execute-all')
execute_workflow_parser.add_argument('workflow_id')
execute_workflow_parser.add_argument('dataset_id', help='Start execution on all documents in dataset')
execute_workflow_parser.set_defaults(cmd=execute_all_workflow)

list_executions_parser = subparsers.add_parser('list-executions')
list_executions_parser.add_argument('workflow_id')
list_executions_parser.add_argument('--status', '-s', nargs='+', help='Only return those with the given status')
Expand Down
Loading