def EndProcess(self, ledger_id: int) -> None: process = self._processes[ledger_id] process.join(timeout=1) if process.is_alive(): raise TypeError( "EndProcess() called on process that is still alive.") self.ledger.Update(self.Get(alice_pb2.LedgerEntry(id=ledger_id), None))
def test_LedgerSerivce_Update_stderr( stub: alice_pb2_grpc.LedgerStub, mock_worker_bee: alice_pb2.String, mock_run_request: alice_pb2.RunRequest, ): """Check that stderr can be set and got.""" stub.RegisterWorkerBee(mock_worker_bee) ledger_id = stub.Add(mock_run_request) stub.Update(alice_pb2.LedgerEntry(id=ledger_id.id, stderr="Hello, stderr!")) entry = stub.Get(ledger_id) assert entry.stderr == "Hello, stderr!" stub.Update(alice_pb2.LedgerEntry(id=ledger_id.id, stderr="abcd")) entry = stub.Get(ledger_id) assert entry.stderr == "abcd"
def test_LedgerSerivce_Update_returncode( stub: alice_pb2_grpc.LedgerStub, mock_worker_bee: alice_pb2.String, mock_run_request: alice_pb2.RunRequest, ): """Check that returncode can be set and got.""" stub.RegisterWorkerBee(mock_worker_bee) ledger_id = stub.Add(mock_run_request) stub.Update(alice_pb2.LedgerEntry(id=ledger_id.id, returncode=123)) entry = stub.Get(ledger_id) assert entry.returncode == 123
def ToProto(self) -> alice_pb2.LedgerEntry: return alice_pb2.LedgerEntry( id=self.id, worker_id=self.worker_id, uname=self.uname, # TODO: Run request? job_status=self.job_status, job_outcome=self.job_outcome, build_start_unix_epoch_ms=labdate.MillisecondsTimestamp( self.build_started), run_start_unix_epoch_ms=labdate.MillisecondsTimestamp( self.run_started), run_end_unix_epoch_ms=labdate.MillisecondsTimestamp(self.run_end), returncode=self.returncode, )
def Get(self, request: alice_pb2.LedgerId, context) -> alice_pb2.LedgerEntry: process = self._processes[request.id] returncode = process.returncode if returncode is None: outcome = alice_pb2.LedgerEntry.UNKNOWN elif returncode == 0: outcome = alice_pb2.LedgerEntry.RUN_SUCCEEDED else: outcome = alice_pb2.LedgerEntry.RUN_FAILED return alice_pb2.LedgerEntry( id=request.id, job_status=(alice_pb2.LedgerEntry.RUNNING if process.is_alive() else alice_pb2.LedgerEntry.COMPLETE), job_outcome=outcome, stdout=process.stdout, stderr=process.stderr, returncode=returncode, )
def Add(self, request: alice_pb2.RunRequest, context) -> alice_pb2.LedgerId: del context with self.db.Session(commit=True) as s: entry = LedgerEntry(**LedgerEntry.FromProto( alice_pb2.LedgerEntry( job_status=alice_pb2.LedgerEntry.BUILDING, run_request=request, ))) s.add(entry) s.flush() entry_id = entry.id app.Log(1, "Created new ledger entry %s", entry_id) worker_bee = self.SelectWorkerIdForRunRequest(request) entry.worker_id = worker_bee.id request.ledger_id = entry_id worker_bee.Run(request, None) return alice_pb2.LedgerId(id=entry_id)
def Get(self, request: alice_pb2.LedgerId, context) -> alice_pb2.Null: """Mock Run() which does nothing.""" del request del context return alice_pb2.LedgerEntry()