-
-
Save bartolsthoorn/d272861d88d80a7bf232 to your computer and use it in GitHub Desktop.
Scraper class (for jobs)
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
#!/usr/bin/env rake | |
require "resque/tasks" | |
task 'resque:setup' do | |
require_relative 'scraper.rb' | |
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
require 'resque' | |
require 'resque/plugins/lock' | |
class Scraper | |
extend Resque::Plugins::Lock | |
@queue = :url_serve | |
#def self.lock(host, url) | |
# host | |
#end | |
def self.perform(host, url) | |
File.open('scraper.log', 'a') do |f| | |
f.write(Time.now.to_s+" "+url+"\n") | |
end | |
return url | |
end | |
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
require_relative 'scraper.rb' | |
requests = [ | |
{ | |
:host => "bartolsthoorn.nl", | |
:url => "http://bartolsthoorn.nl" | |
}, | |
{ | |
:host => "bartlab.nl", | |
:url => "http://bartlab.nl" | |
}, | |
{ | |
:host => "bartolsthoorn.nl", | |
:url => "http://bartolsthoorn.nl/contact" | |
}, | |
{ | |
:host => "bartlab.nl", | |
:url => "http://bartlab.nl/contact" | |
} | |
] | |
#Does not work: | |
#Resque.redis = 'localhost:6379' | |
requests.each do |request| | |
#Equivalent: Scraper.perform request[:host], request[:url] | |
Resque.enqueue(Scraper, request[:host], request[:url]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment