88from grpclib import server
99from grpclib .health .service import Health
1010
11+ from golem_task_api .dirutils import ProviderTaskDir , RequestorDir
1112from golem_task_api .proto .golem_task_api_grpc import (
1213 ProviderAppBase ,
1314 RequestorAppBase ,
@@ -63,15 +64,14 @@ def __init__(
6364 handler : RequestorAppHandler ,
6465 lifecycle : AppLifecycleHandler ,
6566 ) -> None :
66- self ._work_dir = work_dir
67+ self ._work_dir = RequestorDir ( work_dir )
6768 self ._handler = handler
6869 self ._lifecycle = lifecycle
6970
7071 @forward_exceptions ()
7172 async def CreateTask (self , stream ):
7273 request : CreateTaskRequest = await stream .recv_message ()
73- task_id = request .task_id
74- task_work_dir = self ._work_dir / task_id
74+ task_work_dir = self ._work_dir .task_dir (request .task_id )
7575 max_subtasks_count = request .max_subtasks_count
7676 task_params = json .loads (request .task_params_json )
7777 task = await self ._handler .create_task (
@@ -87,9 +87,8 @@ async def CreateTask(self, stream):
8787 @forward_exceptions ()
8888 async def NextSubtask (self , stream ):
8989 request : NextSubtaskRequest = await stream .recv_message ()
90- task_id = request .task_id
90+ task_work_dir = self . _work_dir . task_dir ( request .task_id )
9191 opaque_node_id = request .opaque_node_id
92- task_work_dir = self ._work_dir / task_id
9392 reply = NextSubtaskReply ()
9493 subtask = await self ._handler .next_subtask (
9594 task_work_dir , opaque_node_id )
@@ -104,9 +103,8 @@ async def NextSubtask(self, stream):
104103 @forward_exceptions ()
105104 async def Verify (self , stream ):
106105 request : VerifyRequest = await stream .recv_message ()
107- task_id = request .task_id
106+ task_work_dir = self . _work_dir . task_dir ( request .task_id )
108107 subtask_id = request .subtask_id
109- task_work_dir = self ._work_dir / task_id
110108 result , reason = await self ._handler .verify (task_work_dir , subtask_id )
111109 reply = VerifyReply ()
112110 reply .result = result .value
@@ -117,9 +115,8 @@ async def Verify(self, stream):
117115 @forward_exceptions ()
118116 async def DiscardSubtasks (self , stream ):
119117 request : DiscardSubtasksRequest = await stream .recv_message ()
120- task_id = request .task_id
118+ task_work_dir = self . _work_dir . task_dir ( request .task_id )
121119 subtask_ids = request .subtask_ids
122- task_work_dir = self ._work_dir / task_id
123120 discarded_subtask_ids = \
124121 await self ._handler .discard_subtasks (task_work_dir , subtask_ids )
125122 reply = DiscardSubtasksReply ()
@@ -137,7 +134,7 @@ async def RunBenchmark(self, stream):
137134 @forward_exceptions ()
138135 async def HasPendingSubtasks (self , stream ):
139136 request : HasPendingSubtasksRequest = await stream .recv_message ()
140- task_work_dir = self ._work_dir / request .task_id
137+ task_work_dir = self ._work_dir . task_dir ( request .task_id )
141138 has_pending_subtasks = \
142139 await self ._handler .has_pending_subtasks (task_work_dir )
143140 reply = HasPendingSubtasksReply ()
@@ -159,7 +156,7 @@ def __init__(
159156 handler : ProviderAppHandler ,
160157 lifecycle : AppLifecycleHandler ,
161158 ) -> None :
162- self ._work_dir = work_dir
159+ self ._work_dir = ProviderTaskDir ( work_dir )
163160 self ._handler = handler
164161 self ._lifecycle = lifecycle
165162
0 commit comments