2016-12-27 10:32:49 -07:00
|
|
|
# A device will emit logs when events occur on the Raspberry Pi. Logs are then
|
|
|
|
# read by clients. Logs are only created by devices.
|
2017-07-28 08:47:15 -06:00
|
|
|
class Log < ApplicationRecord
|
2018-06-09 10:58:01 -06:00
|
|
|
include LogDeliveryStuff
|
2018-03-30 09:36:28 -06:00
|
|
|
# We use log.type to store the log's type.
|
2019-02-19 19:10:08 -07:00
|
|
|
# Rails wants to use that name for single table inheritance, which we don't
|
2018-03-30 09:36:28 -06:00
|
|
|
# need for this table.
|
2019-02-19 19:10:08 -07:00
|
|
|
# Setting the `inheritance_column` to "none" alleviate
|
2018-03-30 09:36:28 -06:00
|
|
|
self.inheritance_column = "none"
|
2016-12-27 10:32:49 -07:00
|
|
|
# Used by the frontend to pull most recent records. We don't currently support
|
|
|
|
# pagination, but could later on.
|
2016-12-07 14:23:26 -07:00
|
|
|
PAGE_SIZE = 25
|
2017-12-08 14:12:22 -07:00
|
|
|
|
2018-08-16 08:59:38 -06:00
|
|
|
# Why "EMAIL_ISH"? Because `fatal_email` is LIKE '%email%', but it's probably
|
|
|
|
# not the one you want.
|
2019-03-11 10:44:22 -06:00
|
|
|
IS_EMAIL_ISH = "channels LIKE '%email%'"
|
2018-05-24 11:16:16 -06:00
|
|
|
IS_FATAL_EMAIL = "channels LIKE '%fatal_email%'"
|
2019-03-11 10:44:22 -06:00
|
|
|
DISCARD = ["fun", "debug", nil]
|
|
|
|
TYPES = CeleryScriptSettingsBag::ALLOWED_MESSAGE_TYPES
|
2016-12-27 10:32:49 -07:00
|
|
|
# The means by which the message will be sent. Ex: frontend toast notification
|
2019-03-11 10:44:22 -06:00
|
|
|
serialize :channels
|
2016-12-06 11:58:46 -07:00
|
|
|
belongs_to :device
|
|
|
|
|
2016-12-07 08:48:20 -07:00
|
|
|
validates :device, presence: true
|
2019-03-11 10:44:22 -06:00
|
|
|
validates :type, presence: true
|
2016-12-06 11:58:46 -07:00
|
|
|
# http://stackoverflow.com/a/5127684/1064917
|
|
|
|
before_validation :set_defaults
|
2018-03-25 16:11:17 -06:00
|
|
|
|
2016-12-06 11:58:46 -07:00
|
|
|
def set_defaults
|
|
|
|
self.channels ||= []
|
2018-03-30 09:36:28 -06:00
|
|
|
end
|
|
|
|
|
2017-11-05 10:36:24 -07:00
|
|
|
def broadcast? # Logs get their own special channel. Don't echo twice!
|
2017-11-07 09:50:18 -07:00
|
|
|
false
|
2017-11-05 10:36:24 -07:00
|
|
|
end
|
2017-05-25 08:28:47 -06:00
|
|
|
end
|