Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Resource < ActiveRecord::Base
belongs_to :host
has_many :resource_statuses
has_many :resource_contents
attr_accessible :path, :period, :csspaths
validates_presence_of :path, :period, :csspaths
before_save do |resource|
csspaths = resource.csspaths.split(",")
csspaths.delete("")
resource.csspaths = csspaths.join(",")
end
after_create do |resource|
Delayed::Job.enqueue Periodic::ResourceProbeJob.new(resource), { run_at: 120.seconds.from_now }
self.delay.initial_probe
end
after_save do |resource|
Delayed::Job.enqueue Periodic::ResourceContentProbeJob.new(resource), { run_at: 180.seconds.from_now }
end
def initial_probe
resource_analyze = StatusChecks::ResourceProbe.new(self)
self.resource_statuses.create(code: resource_analyze.code, timeout: resource_analyze.timeout,
is_changed: true, distance: 0, timestamp: Time.current)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment