Skip to content

Commit

Permalink
register run info when initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed Nov 28, 2022
1 parent 927ade3 commit d2c9eba
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
3 changes: 2 additions & 1 deletion nextline/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ async def initialize(self, state: State):
self.result = None
self.exception = None
await self.registrar.state_initialized(self.run_no)
await self.registrar.run_initialized(self.run_no)
await self.registrar.state_change(state)
self.state = state

Expand All @@ -122,7 +123,7 @@ async def run(self, state: State) -> RunInProcess:
filename=self.filename,
),
)
await self.registrar.run_start(self.run_no)
await self.registrar.run_start()
await self.registrar.state_change(state)
self.state = state
return self.future
Expand Down
11 changes: 9 additions & 2 deletions nextline/registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ async def state_change(self, state: State) -> None:
async def state_initialized(self, run_no: int) -> None:
await self._registry.publish("run_no", run_no)

async def run_start(self, run_no: RunNo) -> None:
async def run_initialized(self, run_no: RunNo) -> None:
self._run_info = RunInfo(
run_no=run_no,
state="running",
state="initialized",
script=self._registry.latest("statement"),
)
await self._registry.publish("run_info", self._run_info)

async def run_start(self) -> None:
self._run_info = dataclasses.replace(
self._run_info,
state="running",
started_at=datetime.datetime.now(),
)
await self._registry.publish("run_info", self._run_info)
Expand Down
12 changes: 10 additions & 2 deletions tests/scenarios/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ async def assert_subscribe_run_info(nextline: Nextline, statement: str):
[
info := RunInfo(
run_no=RunNo(1),
state="running",
state="initialized",
script=statement,
result=None,
exception=None,
),
info := dataclasses.replace(
info,
state="running",
started_at=datetime.datetime.now(),
),
dataclasses.replace(
Expand All @@ -90,10 +94,14 @@ async def assert_subscribe_run_info(nextline: Nextline, statement: str):
),
info := RunInfo(
run_no=RunNo(2),
state="running",
state="initialized",
script=statement,
result=None,
exception=None,
),
info := dataclasses.replace(
info,
state="running",
started_at=datetime.datetime.now(),
),
dataclasses.replace(
Expand Down
6 changes: 5 additions & 1 deletion tests/scenarios/test_interruption.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ async def assert_subscribe_run_info(nextline: Nextline, statement: str):
[
info := RunInfo(
run_no=RunNo(1),
state="running",
state="initialized",
script=statement,
result=None,
exception=None,
),
info := dataclasses.replace(
info,
state="running",
started_at=datetime.datetime.now(),
),
dataclasses.replace(
Expand Down
6 changes: 5 additions & 1 deletion tests/scenarios/test_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ async def assert_subscribe_run_info(nextline: Nextline, statement: str):
[
info := RunInfo(
run_no=RunNo(1),
state="running",
state="initialized",
script=statement,
result=None,
exception=None,
),
info := dataclasses.replace(
info,
state="running",
started_at=datetime.datetime.now(),
),
dataclasses.replace(
Expand Down

0 comments on commit d2c9eba

Please sign in to comment.