Skip to content
Snippets Groups Projects
Commit 7c1bd897 authored by Florian Gransee's avatar Florian Gransee Committed by Bert Palm
Browse files

thing abstraction for crontab setup

parent c50dcdce
No related branches found
No related tags found
3 merge requests!290C itest,!289some generic fixes and cleanup,!283492 add thing abstraction to services
......@@ -828,7 +828,7 @@ services:
condition: service_healthy
environment:
LOG_LEVEL: "${LOG_LEVEL}"
TOPIC: thing_creation
TOPIC: configdb_update
MQTT_BROKER: mqtt-broker:1883
MQTT_USER: "${MQTT_USER}"
MQTT_PASSWORD: "${MQTT_PASSWORD}"
......@@ -837,6 +837,12 @@ services:
MQTT_QOS: "${MQTT_QOS}"
DB_API_BASE_URL: "${DB_API_BASE_URL}"
JOURNALING: "${JOURNALING}"
CONFIGDB_DSN: "postgresql://\
${CONFIGDB_USER}:\
${CONFIGDB_PASSWORD}@\
${CONFIGDB_HOST}:\
${CONFIGDB_PORT}/\
${CONFIGDB_DB}"
entrypoint: ["python3", "setup_crontab.py"]
volumes:
- ./cron/crontab.txt:/tmp/cron/crontab.txt
......
......@@ -7,9 +7,10 @@ from random import randint
from crontab import CronItem, CronTab
from timeio.mqtt import AbstractHandler, MQTTMessage
from timeio.thing import Thing
from timeio.feta import Thing
from timeio.common import get_envvar, setup_logging
from timeio.journaling import Journal
from timeio.typehints import MqttPayload
logger = logging.getLogger("crontab-setup")
journal = Journal("Cron")
......@@ -27,9 +28,10 @@ class CreateThingInCrontabHandler(AbstractHandler):
mqtt_clean_session=get_envvar("MQTT_CLEAN_SESSION", cast_to=bool),
)
self.tabfile = "/tmp/cron/crontab.txt"
self.configdb_dsn = get_envvar("CONFIGDB_DSN")
def act(self, content: dict, message: MQTTMessage):
thing = Thing.get_instance(content)
def act(self, content: MqttPayload.ConfigDBUpdate, message: MQTTMessage):
thing = Thing.from_uuid(content["thing"], dsn=self.configdb_dsn)
with CronTab(tabfile=self.tabfile) as crontab:
for job in crontab:
if self.job_belongs_to_thing(job, thing):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment