Farmbot-Web-App/app/models/log.rb

37 lines
1.2 KiB
Ruby
Raw Normal View History

# A device will emit logs when events occur on the Raspberry Pi. Logs are then
# read by clients. Logs are only created by devices.
class Log < ApplicationRecord
include LogDeliveryStuff
# 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
# need for this table.
2019-02-19 19:10:08 -07:00
# Setting the `inheritance_column` to "none" alleviate
self.inheritance_column = "none"
# 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
# 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
# The means by which the message will be sent. Ex: frontend toast notification
2019-03-11 10:44:22 -06:00
serialize :channels
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
# http://stackoverflow.com/a/5127684/1064917
before_validation :set_defaults
2018-03-25 16:11:17 -06:00
def set_defaults
self.channels ||= []
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