Permalink
Browse files

adds delayed job for domains

  • Loading branch information...
Bettina Steger
Bettina Steger committed May 4, 2010
1 parent aa6ddef commit 209f3ec153fdbebb5da90cb068dad40785de5125
Showing with 41 additions and 26 deletions.
  1. +7 −0 Rakefile
  2. +6 −4 app/controllers/domains_controller.rb
  3. +25 −22 app/models/domain.rb
  4. +3 −0 config/initializers/delayed_job_config.rb
View
@@ -8,3 +8,10 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
begin
require 'delayed/tasks'
rescue LoadError
STDERR.puts "Run `rake gems:install` to install delayed_job"
end
@@ -49,9 +49,11 @@ def edit
# POST /domains.xml
def create
@domain = Domain.new(params[:domain])
respond_to do |format|
if @domain.save_with_config
if @domain.save
Delayed::Job.enqueue Domain.find(@domain.id)
#Domain.delay.write_config(@domain)
flash[:notice] = 'Domain was successfully created.'
format.html { redirect_to(@domain) }
format.xml { render :xml => @domain, :status => :created, :location => @domain }
@@ -70,7 +72,7 @@ def update
respond_to do |format|
if @domain.update_attributes(params[:domain])
@domain.save_with_config
Delayed::Job.enqueue Domain.find(@domain.id)
flash[:notice] = 'Domain was successfully updated.'
format.html { redirect_to(@domain) }
format.xml { head :ok }
@@ -86,7 +88,7 @@ def update
# DELETE /domains/1.xml
def destroy
@domain = Domain.find(params[:id])
@domain.destroy
@domain.destroy_with_config
respond_to do |format|
format.html { redirect_to(domains_url) }
View
@@ -6,8 +6,11 @@ class Domain < ActiveRecord::Base
validates_length_of :fqdn, :minimum => 4
validates_presence_of :user_id
def save_with_config
save
def perform
write_config
end
def write_config
begin
servername = self.fqdn
@@ -20,11 +23,11 @@ def save_with_config
Dir.chdir(VHOST_TARGET_DIR) #definend in config/initializers/gccp.rb
puts Dir.pwd
#File.open('gccp_' + servername, "w") do |f|
File.open(servername, "w") do |f|
File.open('gccp_' + servername, "w") do |f|
#File.open(servername, "w") do |f|
f.write(vhost_template)
end
system("a2ensite #{servername}")
system("a2ensite gccp_#{servername}")
system("etc/init.d/apache2 reload")
#system("etc/init.d/apache2 restart")
@@ -43,22 +46,22 @@ def read_template(file)
IO.read(RAILS_ROOT + '/app/templates/'+file)
end
def destroy_config
destroy
begin
servername = self.fqdn
folder = self.mount_point
system("a2dissite #{servername}")
Dir.rmdir(WWW_DIR+folder)
system("etc/init.d/apache2 reload")
Dir.chdir(VHOST_TARGET_DIR) #definend in config/initializers/gccp.rb
File.delete(servername) if File.exist?
rescue Errno::ENOENT
puts "No such directory"
end
def destroy_with_config
transaction do
destroy
begin
servername = self.fqdn
folder = self.mount_point
system("a2dissite gccp_#{servername}")
system("etc/init.d/apache2 reload")
Dir.chdir(VHOST_TARGET_DIR) #definend in config/initializers/gccp.rb
File.delete('gccp_'+servername) if File.exist?('gccp_'+servername)
rescue Errno::ENOENT
puts "No such directory"
end
end
end
end
@@ -0,0 +1,3 @@
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.max_attempts = 5
Delayed::Worker.max_run_time = 30.minutes

0 comments on commit 209f3ec

Please sign in to comment.