-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1) can run multiple runner (daemon) for the scheduler, each runner will listen to the `scheduler_queue`, and the prefetch_count is set to 1, thus each runner can only launch one Scheduler process. 2) The scheduler process listen to the `workgraph_queue` to launch WorkGraph 3) the scheduler recieve rpc call to launch WorkGrpah 4) user can submit workgraph to the workgraph queue, or select the shceduler to run it by pk
- Loading branch information
1 parent
d267263
commit a791b9d
Showing
8 changed files
with
203 additions
and
125 deletions.
There are no files selected for viewing
This file contains 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 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 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,65 @@ | ||
from plumpy.process_comms import RemoteProcessThreadController | ||
from typing import Any, Optional | ||
|
||
|
||
def create_daemon_runner( | ||
manager, queue_name: str = None, loop: Optional["asyncio.AbstractEventLoop"] = None | ||
) -> "Runner": | ||
"""Create and return a new daemon runner. | ||
This is used by workers when the daemon is running and in testing. | ||
:param loop: the (optional) asyncio event loop to use | ||
:return: a runner configured to work in the daemon configuration | ||
""" | ||
from plumpy.persistence import LoadSaveContext | ||
from aiida.engine import persistence | ||
from aiida.engine.processes.launcher import ProcessLauncher | ||
from plumpy.communications import convert_to_comm | ||
|
||
runner = manager.create_runner(broker_submit=True, loop=loop) | ||
runner_loop = runner.loop | ||
# Listen for incoming launch requests | ||
task_receiver = ProcessLauncher( | ||
loop=runner_loop, | ||
persister=manager.get_persister(), | ||
load_context=LoadSaveContext(runner=runner), | ||
loader=persistence.get_object_loader(), | ||
) | ||
|
||
def callback(_comm, msg): | ||
print("Received message: {}".format(msg)) | ||
import asyncio | ||
|
||
asyncio.run(task_receiver(_comm, msg)) | ||
print("task_receiver._continue done") | ||
return True | ||
|
||
assert runner.communicator is not None, "communicator not set for runner" | ||
if queue_name is not None: | ||
print("queue_name: {}".format(queue_name)) | ||
queue = runner.communicator._communicator.task_queue( | ||
queue_name, prefetch_count=1 | ||
) | ||
# queue.add_task_subscriber(callback) | ||
# important to convert the callback | ||
converted = convert_to_comm(task_receiver, runner.communicator._loop) | ||
queue.add_task_subscriber(converted) | ||
else: | ||
runner.communicator.add_task_subscriber(task_receiver) | ||
return runner | ||
|
||
|
||
class ControllerWithQueueName(RemoteProcessThreadController): | ||
def __init__(self, queue_name: str, **kwargs): | ||
super().__init__(**kwargs) | ||
self.queue_name = queue_name | ||
|
||
def task_send(self, message: Any, no_reply: bool = False) -> Optional[Any]: | ||
""" | ||
Send a task to be performed using the communicator | ||
:param message: the task message | ||
:param no_reply: if True, this call will be fire-and-forget, i.e. no return value | ||
:return: the response from the remote side (if no_reply=False) | ||
""" | ||
queue = self._communicator.task_queue(self.queue_name) | ||
return queue.task_send(message, no_reply=no_reply) |
This file contains 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 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
Oops, something went wrong.