77import threading
88import time
99import typing as t
10- from builtins import chr , object , str
10+ from builtins import chr , str
1111from datetime import datetime
12- from functools import total_ordering
1312from queue import Queue
1413
1514import paho .mqtt .client as paho
1817import mqttwarn .configuration
1918from mqttwarn .context import FunctionInvoker , RuntimeContext
2019from mqttwarn .cron import PeriodicThread
21- from mqttwarn .model import StatusInformation
20+ from mqttwarn .model import Job , Service , StatusInformation , Struct
2221from mqttwarn .util import (
2322 Formatter ,
24- Struct ,
2523 asbool ,
2624 load_function ,
2725 load_module_by_name ,
7371service_plugins : t .Dict [str , t .Dict [str , t .Any ]] = dict ()
7472
7573
76- # Class with helper functions which is passed to each plugin
77- # and its global instantiation
78- class Service (object ):
79- def __init__ (self , mqttc , logger ):
80-
81- # Reference to MQTT client object
82- self .mqttc = mqttc
83-
84- # Reference to all mqttwarn globals, for using its machinery from plugins
85- self .mwcore = globals ()
86-
87- # Reference to logging object
88- self .logging = logger
89-
90- # Name of self ("mqttwarn", mostly)
91- self .SCRIPTNAME = SCRIPTNAME
92-
93-
9474def make_service (mqttc = None , name = None ):
9575 """
9676 Service object factory.
@@ -103,37 +83,10 @@ def make_service(mqttc=None, name=None):
10383 """
10484 name = name or "unknown"
10585 logger = logging .getLogger (name )
106- service = Service (mqttc , logger )
86+ service = Service (mqttc = mqttc , logger = logger , mwcore = globals (), program = SCRIPTNAME )
10787 return service
10888
10989
110- @total_ordering
111- class Job (object ):
112- def __init__ (self , prio , service , section , topic , payload , data , target ):
113- self .prio = prio
114- self .service = service
115- self .section = section
116- self .topic = topic
117- self .payload = payload # raw payload
118- self .data = data # decoded payload
119- self .target = target
120-
121- logger .debug ("New `%s:%s' job: %s" % (service , target , topic ))
122- return
123-
124- # The `__cmp__()` special method is no longer honored in Python 3.
125- # https://portingguide.readthedocs.io/en/latest/comparisons.html#rich-comparisons
126-
127- def __eq__ (self , other ):
128- return self .prio == other .prio
129-
130- def __ne__ (self , other ):
131- return not (self .prio == other .prio )
132-
133- def __lt__ (self , other ):
134- return self .prio < other .prio
135-
136-
13790def render_template (filename , data ):
13891 text = None
13992 if HAVE_JINJA is True :
@@ -352,6 +305,7 @@ def get_key(item):
352305 sendtos = [target ]
353306
354307 for sendto in sendtos :
308+ logger .debug ("New `%s:%s' job: %s" % (service , sendto , topic ))
355309 job = Job (1 , service , section , topic , payload , data , sendto )
356310 q_in .put (job )
357311
0 commit comments