mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 01:33:36 +02:00
Add whenever and zonefile methods
This commit is contained in:
parent
4e8b100f5c
commit
603cfb61ef
7 changed files with 56 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,6 +12,7 @@ capybara-*.html
|
|||
config/initializers/secret_token.rb
|
||||
config/secrets.yml
|
||||
config/database.yml
|
||||
/export
|
||||
|
||||
## Environment normalisation:
|
||||
/.bundle
|
||||
|
|
3
Gemfile
3
Gemfile
|
@ -75,6 +75,9 @@ gem 'delayed_job_active_record', '~> 4.0.2'
|
|||
# to process delayed jobs
|
||||
gem 'daemons'
|
||||
|
||||
# cron
|
||||
gem 'whenever', '~> 0.9.4', require: false
|
||||
|
||||
group :development, :test do
|
||||
# for inserting dummy data
|
||||
gem 'activerecord-import', '~> 0.6.0'
|
||||
|
|
|
@ -69,6 +69,7 @@ GEM
|
|||
xpath (~> 2.0)
|
||||
celluloid (0.16.0)
|
||||
timers (~> 4.0.0)
|
||||
chronic (0.10.2)
|
||||
cliver (0.3.2)
|
||||
coderay (1.1.0)
|
||||
coercible (1.0.0)
|
||||
|
@ -353,6 +354,8 @@ GEM
|
|||
railties (~> 4.0)
|
||||
sprockets-rails (>= 2.0, < 4.0)
|
||||
websocket-driver (0.3.5)
|
||||
whenever (0.9.4)
|
||||
chronic (>= 0.6.3)
|
||||
xpath (2.0.0)
|
||||
nokogiri (~> 1.3)
|
||||
|
||||
|
@ -412,3 +415,4 @@ DEPENDENCIES
|
|||
unicorn
|
||||
uuidtools (~> 2.1.4)
|
||||
web-console (~> 2.0.0.beta4)
|
||||
whenever (~> 0.9.4)
|
||||
|
|
|
@ -1,6 +1,22 @@
|
|||
class ZonefileSetting < ActiveRecord::Base
|
||||
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, presence: true
|
||||
validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true }
|
||||
|
||||
def self.generate_zonefiles
|
||||
pluck(:origin).each do |origin|
|
||||
generate_zonefile(origin)
|
||||
end
|
||||
end
|
||||
|
||||
def self.generate_zonefile(origin)
|
||||
zf = ActiveRecord::Base.connection.execute(
|
||||
"select generate_zonefile('#{origin}')"
|
||||
)[0]['generate_zonefile']
|
||||
|
||||
filename = "#{origin}.zone"
|
||||
File.open("#{APP_CONFIG['zonefile_export_dir']}/#{filename}", 'w') { |f| f.write(zf) }
|
||||
end
|
||||
|
||||
def to_s
|
||||
origin
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
defaults: &defaults
|
||||
app_name: .EE Registry
|
||||
zonefile_export_dir: 'export/zonefiles'
|
||||
|
||||
development:
|
||||
<<: *defaults
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'mina/bundler'
|
||||
require 'mina/rails'
|
||||
require 'mina/git'
|
||||
require 'mina/whenever'
|
||||
# require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
|
||||
# require 'mina/rvm' # for rvm support. (http://rvm.io)
|
||||
|
||||
|
@ -31,7 +32,8 @@ set :shared_paths, [
|
|||
'config/database.yml',
|
||||
'config/secrets.yml',
|
||||
'log',
|
||||
'public/system'
|
||||
'public/system',
|
||||
'export/zonefiles'
|
||||
]
|
||||
|
||||
# Optional settings:
|
||||
|
@ -68,6 +70,9 @@ task setup: :environment do
|
|||
queue! %(mkdir -p "#{deploy_to}/shared/public/system")
|
||||
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/public/system")
|
||||
|
||||
queue! %(mkdir -p "#{deploy_to}/shared/export/zonefiles")
|
||||
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/export/zonefiles")
|
||||
|
||||
queue! %(touch "#{deploy_to}/shared/config/database.yml")
|
||||
queue %(echo '-----> Be sure to edit 'shared/config/database.yml'.')
|
||||
end
|
||||
|
@ -82,6 +87,7 @@ task deploy: :environment do
|
|||
invoke :'bundle:install'
|
||||
invoke :'rails:db_migrate'
|
||||
invoke :'rails:assets_precompile'
|
||||
invoke :'whenever:update'
|
||||
|
||||
to :launch do
|
||||
queue "mkdir -p #{deploy_to}/current/tmp; touch #{deploy_to}/current/tmp/restart.txt"
|
||||
|
|
24
config/schedule.rb
Normal file
24
config/schedule.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Use this file to easily define all of your cron jobs.
|
||||
#
|
||||
# It's helpful, but not entirely necessary to understand cron before proceeding.
|
||||
# http://en.wikipedia.org/wiki/Cron
|
||||
|
||||
# Example:
|
||||
#
|
||||
# set :output, "/path/to/my/cron_log.log"
|
||||
#
|
||||
# every 2.hours do
|
||||
# command "/usr/bin/some_great_command"
|
||||
# runner "MyModel.some_method"
|
||||
# rake "some:great:rake:task"
|
||||
# end
|
||||
#
|
||||
# every 4.days do
|
||||
# runner "AnotherModel.prune_old_records"
|
||||
# end
|
||||
|
||||
every 10.minutes do
|
||||
runner 'ZonefileSetting.generate_zonefiles'
|
||||
end
|
||||
|
||||
# Learn more: http://github.com/javan/whenever
|
Loading…
Add table
Add a link
Reference in a new issue