mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 00:12:03 +02:00
Basic delayed job implementation
This commit is contained in:
parent
6aa82dd222
commit
4cedb2cf78
12 changed files with 126 additions and 1 deletions
30
app/models/concerns/domain_version_observer.rb
Normal file
30
app/models/concerns/domain_version_observer.rb
Normal 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
|
|
@ -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') }
|
||||
|
||||
|
|
3
app/models/whois_domain.rb
Normal file
3
app/models/whois_domain.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class WhoisDomain < WhoisServer
|
||||
self.table_name = 'domains'
|
||||
end
|
4
app/models/whois_server.rb
Normal file
4
app/models/whois_server.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class WhoisServer < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
establish_connection :"#{Rails.env}_whois"
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue