Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 08d37139

Přidáno uživatelem Martin Forejt před téměř 4 roky(ů)

Re #8731 - schedule task to close topics

Zobrazit rozdíly:

aswi2021vochomurka/service/mqtt/mqtt_subscriber.py
2 2

  
3 3
from aswi2021vochomurka.service.message_parser import parse_mqtt_message, ParseException
4 4
from aswi2021vochomurka.service.subscriber import Subscriber
5
from apscheduler.schedulers.background import BackgroundScheduler
5 6

  
6 7

  
7 8
class MQTTSubscriber(Subscriber):
9
    sched = BackgroundScheduler()
8 10

  
9 11
    # The callback for when the client receives a CONNACK response from the server.
10 12
    def on_connect(self, client, userdata, flags, rc, properties=None):
11 13
        print("Connected with result code " + str(rc))
12 14
        self.callback.onConnected()
15

  
16
        # start scheduler to check closed topics
17
        self.sched.add_job(self.check_closed_topics, 'interval', seconds=self.params.closeLimit)
18
        self.sched.start()
19

  
13 20
        # Subscribing in on_connect() means that if we lose the connection and
14 21
        # reconnect then subscriptions will be renewed.
15 22
        for topic in self.params.topics:
......
29 36

  
30 37
    def on_disconnect(self, client, userdata, rc):
31 38
        self.callback.onDisconnected()
39
        self.sched.shutdown()
40

  
41
    def check_closed_topics(self):
42
        print('checking closed topics')
43
        pass
32 44

  
33 45
    def start(self):
34 46
        client = mqtt.Client()
aswi2021vochomurka/view/main_view.py
17 17

  
18 18
    params = SubscriberParams(
19 19
        ["/home/1", "/home/2"],
20
        120,
20
        10,
21 21
        ConnectionParams("localhost", 1883, 60),
22 22
        True
23 23
    )

Také k dispozici: Unified diff