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

feat: Async api #60

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

feat: Async api #60

wants to merge 13 commits into from

Conversation

dolfim-ibm
Copy link
Contributor

@dolfim-ibm dolfim-ibm commented Feb 21, 2025

Introduce the Async compute API

# sync (currently in place)
/v1alpha/convert/source
/v1alpha/convert/file

# launch async
/v1alpha/convert/source/async
/v1alpha/convert/file/async

# check status
/v1alpha/status/poll/{task_id}?wait=10
/v1alpha/status/ws/{task_id}

# get result
/v1alpha/result/{task_id}

Still TODO

  • Definition of async api specs
  • Implement first option with a local queue
  • Websockets for push updates
  • Deal with file return type (with return_as_file or multiple inputs)

Issue resolved by this Pull Request:
Resolves #51

Copy link

mergify bot commented Feb 21, 2025

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

Comment on lines +28 to +30
if self.task_status in [TaskStatus.SUCCESS, TaskStatus.FAILURE]:
return True
return False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.task_status in [TaskStatus.SUCCESS, TaskStatus.FAILURE]:
return True
return False
return self.task_status in [TaskStatus.SUCCESS, TaskStatus.FAILURE]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ruff's SIM would suggest this fix

Comment on lines +33 to +38
task_id: str = await self.orchestrator.task_queue.get()
self.orchestrator.queue_list.remove(task_id)

if task_id not in self.orchestrator.tasks:
raise RuntimeError(f"Task {task_id} not found.")
task = self.orchestrator.tasks[task_id]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt this be a part of AsyncLocalOrchestrator API? too easy to make a mistake with 3 separate properties

@dolfim-ibm dolfim-ibm marked this pull request as ready for review February 27, 2025 03:17
Copy link

@cau-git cau-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ Beautiful! Only small comments below.

Comment on lines +32 to +34
self.task_queue = asyncio.Queue()
self.tasks: Dict[str, Task] = {}
self.queue_list: List[str] = []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe one could encapsulate these three members in a class that derives from asyncio.Queue to make it cleaner and less error prone to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this and other refactoring will become more obvious once we implement the other compute engines (redis, etc)
The idea is also to have functionalities in some base class or objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

First version of the async api
3 participants