Skip to content
6 changes: 2 additions & 4 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ package-data.twisted = [ "plugins/recceiver_plugin.py" ]
[tool.ruff]
target-version = "py39"
line-length = 120
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
lint.select = [ "E", "F", "I" ]
# E: pycodestyle errors, F: Pyflakes, G: flake8-logging-format (enforce lazy % in log calls), I: isort.
lint.select = [ "E", "F", "G", "I" ]
Comment thread
anderslindho marked this conversation as resolved.

[tool.pytest]
ini_options.log_level = "DEBUG"
Expand Down
12 changes: 6 additions & 6 deletions server/recceiver/announcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .protocol.announce import ANNOUNCE_PORT, BROADCAST_ADDRESS, Announce

_log = logging.getLogger(__name__)
log = logging.getLogger(__name__)


__all__ = ["Announcer", "SharedUDP"]
Expand Down Expand Up @@ -53,14 +53,14 @@ def __init__(
raise RuntimeError("Announce list is empty at start time...")

def startProtocol(self):
_log.info("Setup Announcer")
log.info("Setup Announcer")
self.D = self.reactor.callLater(0, self.sendOne)
# we won't process any received traffic, so no reason to wake
# up for it...
self.transport.pauseProducing()

def stopProtocol(self):
_log.info("Stop Announcer")
log.info("Stop Announcer")
self.D.cancel()
del self.D

Expand All @@ -71,14 +71,14 @@ def sendOne(self):
self.D = self.reactor.callLater(self.delay, self.sendOne)
for A in self.udps:
try:
_log.debug("announce to {s}".format(s=A))
log.debug("announce to %s", A)
self.transport.write(self.msg, A)
try:
self.udpErr.remove(A)
_log.warning("announce OK to {s}".format(s=A))
log.warning("announce OK to %s", A)
except KeyError:
pass
except MessageLengthError:
if A not in self.udpErr:
self.udpErr.add(A)
_log.exception("announce Error to {s}".format(s=A))
log.exception("announce Error to %s", A)
22 changes: 11 additions & 11 deletions server/recceiver/application.py
Comment thread
anderslindho marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from twisted.application import service
from twisted.internet import defer, pollreactor, task
from twisted.internet.error import CannotListenError
from twisted.python import log, usage
from twisted.python import log as twisted_log
from twisted.python import usage
from zope.interface import implementer

from twisted import plugin
Expand All @@ -16,9 +17,7 @@
from .processors import ProcessorController
from .recast import CastFactory

_log = logging.getLogger(__name__)

pollreactor.install()
log = logging.getLogger(__name__)


class Log2Twisted(logging.StreamHandler):
Expand All @@ -29,7 +28,7 @@ def __init__(self):
# The Twisted log publisher adds a newline,
# so strip the newline added by the Python log handler.
self.terminator = ""
self.write = log.msg
self.write = twisted_log.msg

def flush(self):
# Required by logging.StreamHandler; this handler writes directly to Twisted logs.
Expand Down Expand Up @@ -74,7 +73,7 @@ def __init__(self, config):
self.addrlist = [("<broadcast>", 5049)]

def privilegedStartService(self):
_log.info("Starting RecService")
log.info("Starting RecService")

# Start TCP server on random port
self.tcpFactory = CastFactory()
Expand All @@ -96,7 +95,7 @@ def privilegedStartService(self):

# Find out which port is in use
addr = self.tcp.getHost()
_log.info("RecService listening on {addr}".format(addr=addr))
log.info("RecService listening on %s", addr)

self.key = random.randint(0, 0xFFFFFFFF)

Expand All @@ -117,9 +116,9 @@ def privilegedStartService(self):
if self.metricsPort > 0:
if metrics.available:
self.reactor.listenTCP(self.metricsPort, metrics.make_site(), interface=self.bind)
_log.info("Prometheus metrics available on port %d", self.metricsPort)
log.info("Prometheus metrics available on port %d", self.metricsPort)
else:
_log.warning("metricsPort configured but prometheus_client is not installed; metrics disabled")
log.warning("metricsPort configured but prometheus_client is not installed; metrics disabled")

metrics.connections_limit.set(self.tcpFactory.maxActive)

Expand All @@ -130,15 +129,15 @@ def privilegedStartService(self):
def _logStatus(self):
metrics.connections_active.set(self.tcpFactory.NActive)
metrics.connections_waiting.set(len(self.tcpFactory.Wait))
_log.info(
log.info(
"status: connections active=%d/%d queued=%d",
self.tcpFactory.NActive,
self.tcpFactory.maxActive,
len(self.tcpFactory.Wait),
)

def stopService(self):
_log.info("Stopping RecService")
log.info("Stopping RecService")

if self._statusLoop is not None and self._statusLoop.running:
self._statusLoop.stop()
Expand All @@ -165,6 +164,7 @@ class Maker(object):
options = Options

def make_service(self, opts):
pollreactor.install()
ctrl = ProcessorController(cfile=opts["config"])
conf = ctrl.config("recceiver")
S = RecService(conf)
Expand Down
1 change: 1 addition & 0 deletions server/recceiver/cf/config.py
Comment thread
anderslindho marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def loads(cls, conf: ConfigAdapter) -> "CFConfig":
clean_on_start=conf.getboolean("cleanOnStart", True),
clean_on_stop=conf.getboolean("cleanOnStop", True),
username=conf.get("username", "cfstore"),
env_owner_variable=conf.get("envOwnerVariable", "ENGINEER"),
recceiver_id=conf.get("recceiverId", RECCEIVERID_DEFAULT),
timezone=conf.get("timezone", ""),
cf_query_limit=conf.get("findSizeLimit", DEFAULT_QUERY_LIMIT),
Expand Down
Loading
Loading