Add configurable delay per client; improve try/catch
This commit is contained in:
parent
3f9adfa6c5
commit
4e11748b45
5 changed files with 97 additions and 58 deletions
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2016 Lance Edgar
|
||||
# Copyright © 2010-2017 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -28,6 +28,7 @@ from __future__ import unicode_literals, absolute_import
|
|||
|
||||
import datetime
|
||||
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
@ -39,6 +40,7 @@ from rattail.db.model.core import ModelBase
|
|||
Base = declarative_base(cls=ModelBase)
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Client(Base):
|
||||
"""
|
||||
Represents a tempmon client.
|
||||
|
@ -52,16 +54,23 @@ class Client(Base):
|
|||
config_key = sa.Column(sa.String(length=50), nullable=False)
|
||||
hostname = sa.Column(sa.String(length=255), nullable=False)
|
||||
location = sa.Column(sa.String(length=255), nullable=True)
|
||||
|
||||
delay = sa.Column(sa.Integer(), nullable=True, doc="""
|
||||
Number of seconds to delay between reading / recording temperatures. If
|
||||
not set, a default of 60 seconds will be assumed.
|
||||
""")
|
||||
|
||||
enabled = sa.Column(sa.Boolean(), nullable=False, default=False)
|
||||
online = sa.Column(sa.Boolean(), nullable=False, default=False)
|
||||
|
||||
def __unicode__(self):
|
||||
def __str__(self):
|
||||
return '{} ({})'.format(self.config_key, self.hostname)
|
||||
|
||||
def enabled_probes(self):
|
||||
return [probe for probe in self.probes if probe.enabled]
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Probe(Base):
|
||||
"""
|
||||
Represents a probe connected to a tempmon client.
|
||||
|
@ -103,10 +112,11 @@ class Probe(Base):
|
|||
status_changed = sa.Column(sa.DateTime(), nullable=True)
|
||||
status_alert_sent = sa.Column(sa.DateTime(), nullable=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.description or '')
|
||||
def __str__(self):
|
||||
return self.description
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Reading(Base):
|
||||
"""
|
||||
Represents a single tempurate reading from a tempmon probe.
|
||||
|
@ -136,5 +146,5 @@ class Reading(Base):
|
|||
taken = sa.Column(sa.DateTime(), nullable=False, default=datetime.datetime.utcnow)
|
||||
degrees_f = sa.Column(sa.Numeric(precision=7, scale=4), nullable=False)
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.degrees_f)
|
||||
def __str__(self):
|
||||
return str(self.degrees_f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue