Skip to content

Commit 6317abf

Browse files
Wiezzelmfranciszkiewicz
authored andcommitted
AbortTask RPC call (#52)
1 parent bb1100c commit 6317abf

File tree

9 files changed

+145
-12
lines changed

9 files changed

+145
-12
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ For requestor the app should implement a long running RPC service which implemen
5757
- Takes no arguments.
5858
- Returns a score which indicates how efficient the machine is for this type of tasks.
5959
- Shouldn't take much time (preferably less than a minute for medium range machines).
60+
- `AbortTask`
61+
- Takes one argument: `task_id`.
62+
- Will be called when the task is aborted by the user. Should perform any necessary cleanup.
6063
- `Shutdown`
6164
- Takes no arguments.
6265
- Should gracefully terminate the service.

golem_task_api/proto/golem_task_api.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ service RequestorApp {
99
rpc DiscardSubtasks (DiscardSubtasksRequest) returns (DiscardSubtasksReply) {}
1010
rpc RunBenchmark (RunBenchmarkRequest) returns (RunBenchmarkReply) {}
1111
rpc HasPendingSubtasks (HasPendingSubtasksRequest) returns (HasPendingSubtasksReply) {}
12+
rpc AbortTask (AbortTaskRequest) returns (AbortTaskReply) {}
1213

1314
rpc Shutdown (ShutdownRequest) returns (ShutdownReply) {}
1415
}
@@ -101,6 +102,13 @@ message HasPendingSubtasksReply {
101102
bool has_pending_subtasks = 1;
102103
}
103104

105+
message AbortTaskRequest {
106+
string task_id = 1;
107+
}
108+
109+
message AbortTaskReply {
110+
}
111+
104112

105113
message ShutdownRequest {
106114
}

python/golem_task_api/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
from golem_task_api.enums import VerifyResult
1515
from golem_task_api.messages import (
16+
AbortTaskRequest,
17+
AbortTaskReply,
1618
CreateTaskRequest,
1719
CreateTaskReply,
1820
NextSubtaskRequest,
@@ -241,6 +243,11 @@ async def has_pending_subtasks(self, task_id: str) -> bool:
241243
reply = await self._golem_app.HasPendingSubtasks(request)
242244
return reply.has_pending_subtasks
243245

246+
async def abort_task(self, task_id: str) -> None:
247+
request = AbortTaskRequest()
248+
request.task_id = task_id
249+
await self._golem_app.AbortTask(request)
250+
244251
async def _soft_shutdown(self) -> None:
245252
request = ShutdownRequest()
246253
await self._golem_app.Shutdown(request)

python/golem_task_api/handlers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ async def run_benchmark(self, work_dir: Path) -> float:
7474
pass
7575

7676
@abc.abstractmethod
77-
async def has_pending_subtasks(self, task_work_dir: Path) -> bool:
77+
async def has_pending_subtasks(
78+
self,
79+
task_work_dir: RequestorTaskDir
80+
) -> bool:
81+
pass
82+
83+
@abc.abstractmethod
84+
async def abort_task(self, task_work_dir: RequestorTaskDir) -> None:
7885
pass
7986

8087

python/golem_task_api/messages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from .proto.golem_task_api_pb2 import (
2+
AbortTaskRequest,
3+
AbortTaskReply,
24
CreateTaskRequest,
35
CreateTaskReply,
46
NextSubtaskRequest,

python/golem_task_api/proto/golem_task_api_grpc.py

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/golem_task_api/proto/golem_task_api_pb2.py

Lines changed: 90 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/golem_task_api/server.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
RequestorAppHandler,
2020
)
2121
from golem_task_api.messages import (
22+
AbortTaskRequest,
23+
AbortTaskReply,
2224
CreateTaskRequest,
2325
CreateTaskReply,
2426
ComputeRequest,
@@ -141,6 +143,14 @@ async def HasPendingSubtasks(self, stream):
141143
reply.has_pending_subtasks = has_pending_subtasks
142144
await stream.send_message(reply)
143145

146+
@forward_exceptions()
147+
async def AbortTask(self, stream):
148+
request: AbortTaskRequest = await stream.recv_message()
149+
task_work_dir = self._work_dir.task_dir(request.task_id)
150+
await self._handler.abort_task(task_work_dir)
151+
reply = AbortTaskReply()
152+
await stream.send_message(reply)
153+
144154
@forward_exceptions()
145155
async def Shutdown(self, stream):
146156
await stream.recv_message()

python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='Golem-Task-Api',
5-
version='0.20.0',
5+
version='0.21.0',
66
url='https://github.com/golemfactory/golem/task-api/python',
77
maintainer='The Golem team',
88
maintainer_email='[email protected]',

0 commit comments

Comments
 (0)