Skip to content

Instantly share code, notes, and snippets.

@wyldrodney
Created April 14, 2012 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wyldrodney/2381107 to your computer and use it in GitHub Desktop.
Save wyldrodney/2381107 to your computer and use it in GitHub Desktop.
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