Basic delayed job implementation

This commit is contained in:
Andres Keskküla 2014-11-11 17:00:41 +02:00
parent 6aa82dd222
commit 4cedb2cf78
12 changed files with 126 additions and 1 deletions

View file

@ -0,0 +1,30 @@
module DomainVersionObserver
extend ActiveSupport::Concern
included do
after_save :delayed_whois_update
end
private
def delayed_whois_update
name = domain_name
return unless name
body = snapshot
delay.update_whois(name, body)
end
# not sure we need to pass in the params since i don't know if delayed job has access to
# all the regular attributes and stuff
def update_whois(domain_name, body)
wd = WhoisDomain.find_or_initialize_by(name: domain_name)
wd.body = body
wd.save!
end
def domain_name
name = reify.try(:name)
name = load_snapshot[:domain][:name] if event == 'create'
return name if name
end
end

View file

@ -1,5 +1,6 @@
class DomainVersion < PaperTrail::Version
include UserEvents
include DomainVersionObserver if Setting.whois_enabled # unless Setting.whois_enabled
scope :deleted, -> { where(event: 'destroy') }

View file

@ -0,0 +1,3 @@
class WhoisDomain < WhoisServer
self.table_name = 'domains'
end

View file

@ -0,0 +1,4 @@
class WhoisServer < ActiveRecord::Base
self.abstract_class = true
establish_connection :"#{Rails.env}_whois"
end