Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: most of the time, site registrations would fail because of ti…
…meouts. This should fix it (moved registration to a backgroundrb task).
- Loading branch information
Kieran Pilkington
committed
Oct 31, 2008
1 parent
fc0d27f
commit abd4e15
Showing
5 changed files
with
191 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
<h3>List your site on Kete.net.nz (optional)</h3> | ||
|
||
<% if @site_listing.blank? -%> | ||
<div id="send_information"> | ||
<div id="top_message"><p>Would you like to send your site name, | ||
site url and a short description of your site for to a public list of Kete installations?</p></div> | ||
|
||
<% form_remote_tag ( :url => { :action => 'send_information' }, | ||
:before => "Element.hide('form_fields');Element.show('data-spinner')", | ||
:complete => "Element.hide('data-spinner')", | ||
:href => url_for( :action => 'send_information' ) ) do %> | ||
<div id="form_fields"> | ||
<div id="register_errors"></div> | ||
<div> | ||
<label for="site_description">Site description: <small>(optional)</small></label><br /> | ||
<input type="text" id="site_description" name="site_description" size="45" /> | ||
|
||
<div id="send_information"> | ||
<div id="top_message"> | ||
<p> | ||
Would you like to send your site name, site url and a short description of your site for to a public list of Kete installations? | ||
</p> | ||
</div> | ||
<div><%= submit_tag 'Send Information', :id => 'data-button' -%></div> | ||
|
||
<% form_remote_tag ( :url => { :action => 'send_information' }, | ||
:before => "Element.hide('form_fields'); Element.show('spinner')", | ||
:href => url_for( :action => 'send_information' ) ) do -%> | ||
<div id="form_fields"> | ||
<div id="register_errors"></div> | ||
<div> | ||
<label for="site_description">Site description: <small>(optional)</small></label><br /> | ||
<input type="text" id="site_description" name="site_description" size="45" /> | ||
</div> | ||
<div><%= submit_tag 'Send Information', :id => 'data-button' -%></div> | ||
</div> | ||
<% end -%> | ||
</div> | ||
|
||
<div id="updater"></div> | ||
|
||
<div id="spinner" style="display:none;"> | ||
<img src="/images/indicator.gif" width="16" height="16" alt="Completed. "> | ||
</div> | ||
<% end -%> | ||
</div> | ||
<div id="data-spinner" style="display:none; text-align:center"> | ||
<img src="/images/indicator.gif" width="16" height="16" alt="Sending. " /> | ||
</div> | ||
|
||
<% else -%> | ||
<div id="site_is_listed"> | ||
Kete.net.nz already lists the site. You can see details at | ||
<%= link_to(@site_listing, @site_listing) -%>. | ||
</div> | ||
|
||
<div id="site_is_listed"> | ||
Kete.net.nz already lists the site. You can see details at <%= link_to(@site_listing, @site_listing) -%>. | ||
</div> | ||
|
||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module SiteRegistration | ||
unless included_modules.include? SiteRegistration | ||
def set_kete_net_urls | ||
@kete_net = "http://localhost:3000/site" | ||
@kete_sites = "#{@kete_net}/kete_sites" | ||
@kete_sites_register = "#{@kete_sites}/new" | ||
end | ||
|
||
def check_nessesary_constants_set | ||
raise "Pretty Site Name and Site URL constants are not set, are you sure you restarted your server after you configured your Kete site?" if SITE_URL.blank? || PRETTY_SITE_NAME.blank? | ||
end | ||
|
||
def site_listing | ||
check_nessesary_constants_set | ||
set_kete_net_urls | ||
@site_listing = RegisterSiteResource.find(:all, :params => { :url => SITE_URL }) | ||
if @site_listing.blank? | ||
@site_listing = '' | ||
else | ||
@site_listing = @site_listing.first.attributes | ||
@site_listing = "#{@kete_sites}/#{@site_listing['id']}" | ||
end | ||
end | ||
|
||
def error_registering_site | ||
set_kete_net_urls | ||
top_message = "There was an error linking to your site. " | ||
site_listing | ||
if @site_listing.blank? | ||
top_message += "You can do it manually at <a href='#{@kete_sites_register}'>#{@kete_sites_register}</a>." | ||
else | ||
top_message += "However, it appears that your site is now listed. Please check the listing to make sure it is correct at <a href='#{@site_listing}'>#{@site_listing}</a>." | ||
end | ||
render :update do |page| | ||
page.hide('spinner') | ||
page.replace_html("top_message", top_message) | ||
end | ||
end | ||
end | ||
end | ||
|
||
class RegisterSiteResource < ActiveResource::Base | ||
self.site = "http://localhost:3000/site/" | ||
self.element_name = "kete_site" | ||
self.timeout = 60 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
class SiteRegistrationWorker < BackgrounDRb::MetaWorker | ||
set_worker_name :site_registration_worker | ||
set_no_auto_load true | ||
|
||
include SiteRegistration | ||
|
||
def create(args = nil) | ||
results = { :registration_success => false, | ||
:registration_validation_errors => Array.new, | ||
:registration_complete => false } | ||
|
||
cache[:results] = results | ||
end | ||
|
||
def do_work(args = nil) | ||
@results = cache[:results] | ||
params = args[:params] | ||
|
||
check_nessesary_constants_set | ||
|
||
begin | ||
register = RegisterSiteResource.create(:name => PRETTY_SITE_NAME, :url => SITE_URL, :description => params[:site_description]) | ||
rescue | ||
register = nil | ||
@kete_net_error = $! | ||
end | ||
|
||
if !register.nil? && register && register.errors.empty? && register.id > 0 | ||
@results[:registration_success] = true | ||
elsif !register.nil? && !register.errors.empty? | ||
@results[:registration_validation_errors] = register.errors | ||
else | ||
logger.error("Error linking from Kete.net.nz: " + @kete_net_error) if @kete_net_error | ||
end | ||
|
||
@results[:registration_complete] = true | ||
|
||
cache[:results] = @results | ||
end | ||
|
||
def reset_worker | ||
results = { :registration_success => false, | ||
:registration_validation_errors => Array.new, | ||
:registration_complete => false } | ||
|
||
cache[:results] = results | ||
end | ||
|
||
end |