Move MQTT and HSL startup scripts around

This commit is contained in:
Jan Tuomi
2017-10-26 08:35:48 +03:00
parent 258f6212b8
commit 3b3b45b5ee
5 changed files with 21 additions and 16 deletions
-4
View File
@@ -1,4 +0,0 @@
from . import mqtt
import logging
mqtt.client.loop_start()
+18
View File
@@ -1,5 +1,23 @@
from django.apps import AppConfig
import logging
import sys
from coffee_scale import mqtt
class CoffeeScaleConfig(AppConfig):
name = 'coffee_scale'
def ready(self):
if ('makemigrations' in sys.argv or 'migrate' in sys.argv):
return
try:
logging.info('Connecting to MQTT (coffee scale) at {}...'.format(mqtt.HOST))
logging.info('If there is no confirmation, the MQTT connection has probably failed.')
mqtt.client.connect_async(mqtt.HOST, mqtt.PORT, 60)
mqtt.client.loop_start()
except Exception as ex:
logging.error(ex)
logging.error('Failed to connect to MQTT at {}'.format(mqtt.HOST))
-9
View File
@@ -56,12 +56,3 @@ client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.on_disconnect = on_disconnect
try:
logging.info('Connecting to MQTT at {}...'.format(HOST))
logging.info('If there is no confirmation, the MQTT connection has probably failed.')
client.connect_async(HOST, PORT, 60)
except Exception as ex:
logging.error(ex)
logging.error('Failed to connect to MQTT at {}'.format(HOST))
+2 -2
View File
@@ -16,8 +16,8 @@ class HSLFetcher:
last_fetched = datetime.fromtimestamp(86400) # epoch
INTERVAL = 1 # minutes
logging.info(
"Set up scheduled HSL API fetch every {} minutes".format(INTERVAL))
# logging.info(
# "Set up scheduled HSL API fetch every {} minutes".format(INTERVAL))
def fetch_if_needed(self):
"""Check if new fetch from HSL API is needed."""
+1 -1
View File
@@ -78,7 +78,7 @@ INSTALLED_APPS = [
'webapp',
'members',
'infoscreen',
'coffee_scale',
'coffee_scale.apps.CoffeeScaleConfig',
'rest_framework',
'django_nose',
'bootstrap3',