Skip to content

Commit

Permalink
working, but of order logrulerunner
Browse files Browse the repository at this point in the history
  • Loading branch information
claasga committed Nov 16, 2024
1 parent 4e6cf37 commit 065ba91
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion backend/dps_training_k/deployment/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ RUN eval $(opam env) && opam install --deps-only -y .

# Build and install MonPoly
RUN eval $(opam env) && dune build --release && dune install
ENV PATH="/home/opam/.opam/4.11.1/bin:${PATH}"
ENV PATH="/root/.opam/4.11.1/bin:${PATH}"
# Verify MonPoly installation and PATH
RUN eval $(opam env) &&which monpoly && echo $PATH

Expand Down
2 changes: 1 addition & 1 deletion backend/dps_training_k/game/channel_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def unsubscribe_from_exercise(cls, exercise, subscriber):
def _puplish_obj(cls, obj, exercise):
if exercise in cls._exercise_subscribers:
for subscriber in cls._exercise_subscribers[exercise]:
asyncio.run(subscriber.receive_log_entry(obj))
async_to_sync(subscriber.receive_log_entry(obj))


class LogEntryDispatcher(Observable, ChannelNotifier):
Expand Down
29 changes: 19 additions & 10 deletions backend/dps_training_k/game/templmon/log_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def __init__(self, exercise, log):
def __del__(self):
pass

async def receive_log_entry(self, log_entry):
def receive_log_entry(self, log_entry):
asyncio.run_coroutine_threadsafe(self._receive_log_entry(log_entry), self.loop)

async def _receive_log_entry(self, log_entry):
print("*******************************************")
print("Received log entry: ", log_entry.pk)
monpolified_log_entry = transform(log_entry)
Expand All @@ -70,7 +73,7 @@ async def _launch_monpoly(
self, loop: asyncio.AbstractEventLoop, mfotl_path, sig_path, rewrite=True
):
"""Has to be launched in a separate thread"""
monpoly = await asyncio.create_subprocess_exec(
self.monpoly = await asyncio.create_subprocess_exec(
"monpoly",
"-sig",
sig_path,
Expand All @@ -79,11 +82,14 @@ async def _launch_monpoly(
"" if rewrite else "-no_rw",
env=os.environ.copy(), # Ensure the environment variables are passed
)
loop.call_soon_threadsafe(
target=lambda: asyncio.create_task(self.read_output(monpoly))
)
await self.monpoly_started_event.wait()
return monpoly
"""loop.call_soon_threadsafe(
lambda: asyncio.create_task(self.read_output(self.monpoly))
)"""
asyncio.run_coroutine_threadsafe(self.read_output(self.monpoly), loop)
self.monpoly_started_event.wait()
print("MonPoly instance: ")
print(self.monpoly)
return self.monpoly

def start_log_rule(self):
print(
Expand All @@ -101,11 +107,14 @@ def launch_listener_loop(loop: asyncio.AbstractEventLoop):
threading.Thread(target=launch_listener_loop, args=(self.loop,)).start()
print("started loop")
print("Trying to run monpoly thread")
self.monpoly = asyncio.run(
base_dir = os.path.dirname(os.path.abspath(__file__))
mfotl_path = os.path.join(base_dir, "personnel_check.mfotl")
sig_path = os.path.join(base_dir, "kdps.sig")
asyncio.run(
self._launch_monpoly(
self.loop,
"/home/claas/Desktop/BP/dps.training_k/backend/dps_training_k/game/templmon/personnel_check.mfotl",
"/home/claas/Desktop/BP/dps.training_k/backend/dps_training_k/game/templmon/kdps.sig",
mfotl_path,
sig_path,
)
)
print("Succeeded starting monpoly")
Expand Down

0 comments on commit 065ba91

Please sign in to comment.