Skip to content

Commit

Permalink
Merge pull request #221 from martynia/devel_janusz_pilot_timer_fixes
Browse files Browse the repository at this point in the history
[devel] fix RemoteLogger activation logic; pilot logger timer fixes
  • Loading branch information
fstagni committed Nov 8, 2023
2 parents 0c37f3b + d8dba07 commit b3e6e7a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
7 changes: 4 additions & 3 deletions Pilot/dirac-pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
# print the buffer, so we have a "classic' logger back in sync.
sys.stdout.write(bufContent)
# now the remote logger.
if pilotParams.pilotLogging:
remote = pilotParams.pilotLogging and (pilotParams.loggerURL is not None)
if remote:
# In a remote logger enabled Dirac version we would have some classic logger content from a wrapper,
# which we passed in:
receivedContent = ""
Expand Down Expand Up @@ -97,7 +98,7 @@

log.info("Executing commands: %s" % str(pilotParams.commands))

if pilotParams.pilotLogging:
if remote:
# It's safer to cancel the timer here. Each command has got its own logger object with a timer cancelled by the
# finaliser. No need for a timer in the "else" code segment below.
try:
Expand All @@ -114,6 +115,6 @@
else:
log.error("Command %s could not be instantiated" % commandName)
# send the last message and abandon ship.
if pilotParams.pilotLogging:
if remote:
log.buffer.flush()
sys.exit(-1)
7 changes: 4 additions & 3 deletions Pilot/pilotTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,13 @@ def __init__(self, pilotParams, dummy=""):
"""

self.pp = pilotParams
isPilotLoggerOn = pilotParams.pilotLogging
self.debugFlag = pilotParams.debugFlag
loggerURL = pilotParams.loggerURL
# URL present and the flag is set:
isPilotLoggerOn = pilotParams.pilotLogging and (loggerURL is not None)
interval = pilotParams.loggerTimerInterval

if loggerURL is None:
if not isPilotLoggerOn:
self.log = Logger(self.__class__.__name__, debugFlag=self.debugFlag)
else:
# remote logger
Expand Down Expand Up @@ -1100,7 +1101,7 @@ def __initJSON2(self):
self.pilotLogging = pilotLogging.upper() == "TRUE"
self.loggerURL = pilotOptions.get("RemoteLoggerURL")
# logger buffer flush interval in seconds.
self.loggerTimerInterval = pilotOptions.get("RemoteLoggerTimerInterval", self.loggerTimerInterval)
self.loggerTimerInterval = int(pilotOptions.get("RemoteLoggerTimerInterval", self.loggerTimerInterval))
pilotLogLevel = pilotOptions.get("PilotLogLevel", "INFO")
if pilotLogLevel.lower() == "debug":
self.debugFlag = True
Expand Down
17 changes: 7 additions & 10 deletions Pilot/tests/Test_simplePilotLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import tempfile

try:
from Pilot.pilotTools import CommandBase, PilotParams, RemoteLogger
from Pilot.pilotTools import CommandBase, PilotParams, Logger
except ImportError:
from pilotTools import CommandBase, PilotParams, RemoteLogger
from pilotTools import CommandBase, PilotParams, Logger

import unittest

Expand Down Expand Up @@ -122,14 +122,15 @@ def tearDown(self):
@patch(("sys.argv"))
@patch("subprocess.Popen")
def test_executeAndGetOutput(self, popenMock, argvmock):

argvmock.__getitem__.return_value = [
"-d",
"-g",
"dummyURL",
"-F",
"tests/pilot.json",
]

for size in [1000, 1024, 1025, 2005]:
random_str = "".join(random.choice(string.ascii_letters + "\n") for i in range(size))
if sys.version_info.major == 3:
Expand All @@ -144,14 +145,10 @@ def test_executeAndGetOutput(self, popenMock, argvmock):
self.stderr_mock.write("Errare humanum est!")
self.stderr_mock.seek(0)
pp = PilotParams()
try:
cBase = CommandBase(pp)
# we have a logger URL set, so:
assert isinstance(cBase.log, RemoteLogger)
finally:
# and cancel the timer !
cBase.log.buffer.cancelTimer()

cBase = CommandBase(pp)

assert isinstance(cBase.log, Logger)
popenMock.return_value.stdout = self.stdout_mock
popenMock.return_value.stderr = self.stderr_mock
outData = cBase.executeAndGetOutput("dummy")
Expand Down

0 comments on commit b3e6e7a

Please sign in to comment.