Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add auto selftest w/ fallthrough to scraper js; move scraping info in…
…to scrapings out of session/params; overhaul threads sync method to be properly atomic; redo return method to work better w/ asynch & long times
- Loading branch information
Showing
15 changed files
with
229 additions
and
106 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
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
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
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,4 +1,4 @@ | ||
<%= javascript_tag "top.document.getElementById('status_#{@thread_id}').update('Testing sites #{@offset + 1} through #{@limit+@offset}...');" %> | ||
<%= javascript_tag remote_function(:url => visitations_url(:limit => @limit, :offset => @offset, :thread_id => @thread_id ), :method => :post, | ||
<%= javascript_tag "top.document.getElementById('status_#{@thread_id}').update('Testing sites #{@offset + 1} through #{@scraping.batch_size+@offset}...');" %> | ||
<%= javascript_tag remote_function(:url => visitations_url(:thread_id => @thread_id ), :method => :post, | ||
:with => "'results=' + JSON.stringify(CSSHistory.check_batch(#{@sites.map(&:url).to_json}))" ) | ||
%> |
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,4 +1,4 @@ | ||
<%= "top.document.getElementById('status_#{@thread_id}').update('Testing sites #{@offset + 1} through #{@limit+@offset}...');" %> | ||
<%= remote_function :url => visitations_url(:limit => @limit, :offset => @offset, :thread_id => @thread_id ), :method => :post, | ||
<%= "top.document.getElementById('status_#{@thread_id}').update('Testing sites #{@offset + 1} through #{@scraping.batch_size+@offset}...');" %> | ||
<%= remote_function :url => visitations_url(:thread_id => @thread_id ), :method => :post, | ||
:with => "'results=' + JSON.stringify(CSSHistory.check_batch(#{@sites.map(&:url).to_json}))" | ||
%> |
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,29 @@ | ||
class ScrapingWorker < Workling::Base | ||
Workling::Return::Store.instance = Workling::Return::Store::StarlingReturnStore.new | ||
logfile = File.open("#{RAILS_ROOT}/log/#{RAILS_ENV}-background.log", 'a') | ||
logfile.sync = true | ||
BG_LOGGER = Logger.new(logfile) | ||
BG_LOGGER.debug "#{Time.now.to_s}: Loading ScrapingWorker. Return store: #{Workling.return.inspect}" | ||
|
||
def process_results(options) | ||
Workling.return.set options[:uid], "Starting results calculation..." | ||
scraping = Scraping.find(options[:scraping_id]) | ||
BG_LOGGER.debug "#{Time.now.to_s}: #{options[:uid]}: Starting results for scraping #{scraping.id}" | ||
sites = scraping.found_sites.find(:all, :select => :url).map(&:url) | ||
Workling.return.set options[:uid], "Calculating results... 1/5" | ||
unfound_sites = scraping.unfound_sites.find(:all, :select => :url).map(&:url) | ||
Workling.return.set options[:uid], "Calculating results... 2/5" | ||
pv = scraping.user.probability_vector | ||
Workling.return.set options[:uid], "Calculating results... 3/5" | ||
probabilities = scraping.user.url_probabilities(pv) | ||
Workling.return.set options[:uid], "Calculating results... 4/5" | ||
avg_up = User.avg_url_probabilities pv.keys | ||
Workling.return.set options[:uid], "Calculating results... 5/5" | ||
BG_LOGGER.debug "#{Time.now.to_s}: #{options[:uid]}: Returning results for scraping #{scraping.id}" | ||
|
||
Workling.return.set options[:uid], :sites => sites, :unfound_sites => unfound_sites, :probabilities => probabilities, :avg_up => avg_up | ||
BG_LOGGER.debug "#{Time.now.to_s}: #{options[:uid]}: Processed results for scraping #{scraping.id}" | ||
rescue => e | ||
BG_LOGGER.debug "#{Time.now.to_s}: #{options[:uid]}: ERROR #{e}" | ||
end | ||
end |
Oops, something went wrong.