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

Pawel plesniak/terminate kill fixes #289

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
9 changes: 3 additions & 6 deletions src/drunc/process_manager/interface/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,17 @@ async def dummy_boot(obj:ProcessManagerContext, user:str, n_processes:int, sleep


@click.command('terminate')
@add_query_options(at_least_one=False)
@click.pass_obj
@run_coroutine
async def terminate(obj:ProcessManagerContext, query:ProcessQuery) -> None:
result = await obj.get_driver('process_manager').terminate(
query = query,
)
async def terminate(obj:ProcessManagerContext) -> None:
result = await obj.get_driver('process_manager').terminate()
if not result: return

from drunc.process_manager.utils import tabulate_process_instance_list
obj.print(tabulate_process_instance_list(result.data, 'Terminated process', False))

@click.command('kill')
@add_query_options(at_least_one=False)
@add_query_options(at_least_one=True)
@click.pass_obj
@run_coroutine
async def kill(obj:ProcessManagerContext, query:ProcessQuery) -> None:
Expand Down
8 changes: 4 additions & 4 deletions src/drunc/process_manager/process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def boot(self, br:BootRequest) -> Response:


@abc.abstractmethod
def _terminate_impl(self, q:ProcessQuery) -> ProcessInstanceList:
def _terminate_impl(self) -> ProcessInstanceList:
raise NotImplementedError

# ORDER MATTERS!
Expand All @@ -201,10 +201,10 @@ def _terminate_impl(self, q:ProcessQuery) -> ProcessInstanceList:
action=ActionType.DELETE,
system=SystemType.PROCESS_MANAGER
) # 2nd step
@unpack_request_data_to(ProcessQuery) # 3rd step
def terminate(self, q:ProcessQuery) -> Response:
@unpack_request_data_to(None) # 3rd step
def terminate(self) -> Response:
try:
resp = self._terminate_impl(q)
resp = self._terminate_impl()
return Response(
name = self.name,
token = None,
Expand Down
5 changes: 2 additions & 3 deletions src/drunc/process_manager/process_manager_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,10 @@ async def dummy_boot(self, user:str, session_name:str, n_processes:int, sleep:in
outformat = ProcessInstance,
)

async def terminate(self, query:ProcessQuery) -> ProcessInstanceList:
async def terminate(self, ) -> ProcessInstanceList:
return await self.send_command_aio(
'terminate',
data = query,
outformat = ProcessInstanceList,
outformat = ProcessInstanceList
)

async def kill(self, query:ProcessQuery) -> ProcessInstance:
Expand Down
2 changes: 1 addition & 1 deletion src/drunc/process_manager/ssh_process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def kill_processes(self, uuids:list) -> ProcessInstanceList:
return pil


def _terminate_impl(self, query:ProcessQuery) -> ProcessInstanceList:
def _terminate_impl(self) -> ProcessInstanceList:
self._log.info('Terminating')
if self.process_store:
self._log.warning('Killing all the known processes before exiting')
Expand Down
3 changes: 1 addition & 2 deletions src/drunc/process_manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ def generate_process_query(f, at_least_one:bool, all_processes_by_default:bool=F
@click.pass_context
def new_func(ctx, session, name, user, uuid, **kwargs):
is_trivial_query = bool((len(uuid) == 0) and (session is None) and (len(name) == 0) and (user is None))
# print(f'is_trivial_query={is_trivial_query} ({type(is_trivial_query)}): uuid={uuid} ({type(uuid)}), session={session} ({type(session)}), name={name} ({type(name)}), user={user} ({type(user)})')

if is_trivial_query and at_least_one:
raise click.BadParameter('You need to provide at least a \'--uuid\', \'--session\', \'--user\' or \'--name\'!')
raise click.BadParameter('You need to provide at least a \'--uuid\', \'--session\', \'--user\' or \'--name\'!\nAll these values are presented with \'ps\'.\nIf you want to kill everything, use \'terminate\'.')
plasorak marked this conversation as resolved.
Show resolved Hide resolved

if all_processes_by_default and is_trivial_query:
name = ['.*']
Expand Down