| 
6 | 6 | 
 
  | 
7 | 7 | 
 
  | 
8 | 8 | class Server:  | 
9 |  | -    """  | 
10 |  | -    Server for executing and managing long-running jobs requested by remote clients.  | 
11 |  | -
  | 
12 |  | -    This class provides the server-side counterpart to the Client, responsible for:  | 
13 |  | -
  | 
14 |  | -    1. Registering job handlers that can process long-running tasks  | 
15 |  | -    2. Receiving and validating job requests via RabbitMQ  | 
16 |  | -    3. Managing job execution lifecycle (start, status tracking, result storage)  | 
17 |  | -    4. Providing job status updates to clients  | 
18 |  | -    5. Handling graceful job termination during server shutdown  | 
19 |  | -
  | 
20 |  | -    Internally, the server relies on:  | 
21 |  | -    - RPC Interface: Manages communication and request handling via RabbitMQ  | 
22 |  | -    - Job Interface: Custom implementation that defines how jobs are executed  | 
23 |  | -
  | 
24 |  | -    The server workflow:  | 
25 |  | -    1. Register job handlers during initialization  | 
26 |  | -    2. Listen for incoming job requests on specified RabbitMQ queues  | 
27 |  | -    3. Validate incoming job parameters  | 
28 |  | -    4. Execute jobs in a managed context  | 
29 |  | -    5. Track job status and store results  | 
30 |  | -    6. Respond to client status and result queries  | 
31 |  | -    7. Clean up resources when jobs complete or are terminated  | 
32 |  | -
  | 
33 |  | -    This design allows the server to handle multiple concurrent job requests  | 
34 |  | -    while maintaining job state and providing resilience against server restarts.  | 
35 |  | -    """  | 
36 |  | - | 
37 | 9 |     def __init__(  | 
38 | 10 |         self,  | 
39 | 11 |         rabbit_settings: RabbitSettings,  | 
40 | 12 |         long_running_namespace: LongRunningNamespace,  | 
41 | 13 |         job_interface: BaseServerJobInterface,  | 
42 | 14 |     ) -> None:  | 
 | 15 | +        """Exposes an RPC interface on the server side to run jobs  | 
 | 16 | +
  | 
 | 17 | +        Arguments:  | 
 | 18 | +            rabbit_settings -- settings to connect to RabbitMQ  | 
 | 19 | +            long_running_namespace -- unique namespace for the long-running jobs (allows to regisrter multiple servicer for different pourposes)  | 
 | 20 | +            job_interface -- custom interface for hanlding the execition of the jobs  | 
 | 21 | +        """  | 
43 | 22 |         self.rpc_interface = ServerRPCInterface(  | 
44 | 23 |             rabbit_settings, long_running_namespace, job_interface  | 
45 | 24 |         )  | 
46 | 25 | 
 
  | 
47 |  | -    # TODO: register jobs! and then use the interface to run them!!!  | 
48 |  | - | 
49 | 26 |     async def setup(self) -> None:  | 
50 | 27 |         await self.rpc_interface.setup()  | 
51 | 28 | 
 
  | 
 | 
0 commit comments