-
Notifications
You must be signed in to change notification settings - Fork 0
/
actors.py
30 lines (22 loc) · 996 Bytes
/
actors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
""" Dask actors module. """
import ray
from pricing import PricingRequest
from risk import RiskRequest, RiskResponse
from supervisor import Supervisor
# @ray.remote # Comment this out to use Dask
class PricingActor:
""" Runs pricing requests. """
supervisor: Supervisor
def __init__(self) -> None:
self.supervisor = Supervisor()
async def start(self) -> None:
""" Starts the calculator process. Needs to be called before starting any calculations. """
await self.supervisor.ensure_start()
def stop(self) -> None:
""" Stops the calculator process. """
self.supervisor.stop()
async def calculate_risk(self, request: RiskRequest) -> RiskResponse:
""" Start the calculation on the calculator process. """
pricing_request = PricingRequest(request.batch_name, request.trade)
pricing_response = await self.supervisor.calculate(pricing_request)
return RiskResponse(request, pricing_response.status)