Skip to content

Instantly share code, notes, and snippets.

@n8fischer
Created May 31, 2014 05:19
Show Gist options
  • Save n8fischer/ac95c4804ed62b9dd746 to your computer and use it in GitHub Desktop.
Save n8fischer/ac95c4804ed62b9dd746 to your computer and use it in GitHub Desktop.
def import
if Site.import(params[:file], current_user.id)
redirect_to netwatch_path , notice: "domains imported."
else
redirect_to netwatch_path, notice:"domained failed to import"
end
end
class ReqsWorker
include Sidekiq::Worker
sidekiq_options queue: "high"
# sidekiq_options retry: false
def perform(site_id)
site = Site.find(site_id)
begin
http = Net::HTTP.start("#{site.host}", {open_timeout: 5, read_timeout: 5})
rescue
#return false
end
begin
begin
resp = http.head("/")
if resp.code == "200"
self.update_attributes(alive: true)
else
self.update_attributes(alive: false)
end
rescue Timeout::Error
#time out read
#return false
end
rescue Timeout::Error
#time out connect
#return false
rescue SocketError
#unknown
#return false
end
end
end
2014-05-31T05:10:58Z 16721 TID-byirk INFO: Running in ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
2014-05-31T05:10:58Z 16721 TID-byirk INFO: See LICENSE and the LGPL-3.0 for licensing details.
2014-05-31T05:10:58Z 16721 TID-byirk INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org/pro
2014-05-31T05:10:58Z 16721 TID-byirk INFO: Starting processing, hit Ctrl-C to stop
2014-05-31T05:10:58Z 16721 TID-q6878 INFO: Booting Sidekiq 3.1.2 with redis options {}
2014-05-31T05:10:58Z 16721 TID-gzesc INFO: Booting Sidekiq 3.1.2 with redis options {}
2014-05-31T05:11:08Z 16721 TID-g97zs WARN: {"retry"=>true, "queue"=>"default", "class"=>"HttpreqWorker", "args"=>[1], "jid"=>"3ca3901895220eb5767db1a1", "enqueued_at"=>1401508998.576774, "error_message"=>"uninitialized constant HttpreqWorker::User", "error_class"=>"NameError", "failed_at"=>1401508998.5792215, "retry_count"=>6, "retried_at"=>1401510381.8835053}
2014-05-31T05:11:08Z 16721 TID-g97zs WARN: uninitialized constant HttpreqWorker
2014-05-31T05:11:08Z 16721 TID-g97zs WARN: /home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `const_get'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `block in constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `inject'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-3.1.2/lib/sidekiq/processor.rb:46:in `process'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `public_send'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `dispatch'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:122:in `dispatch'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/actor.rb:322:in `block in handle_message'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/actor.rb:416:in `block in task'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:55:in `block in initialize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/tasks/task_fiber.rb:13:in `block in create'
2014-05-31T05:11:08Z 16721 TID-g97zs WARN: {"retry"=>true, "queue"=>"default", "class"=>"HttpreqWorker", "args"=>[1], "jid"=>"f4209dd96a1050f1929e6888", "enqueued_at"=>1401502238.5783014, "error_message"=>"Couldn't find Site with id=1", "error_class"=>"ActiveRecord::RecordNotFound", "failed_at"=>1401502238.627056, "retry_count"=>8, "retried_at"=>1401507612.7905674}
2014-05-31T05:11:08Z 16721 TID-g97zs WARN: uninitialized constant HttpreqWorker
2014-05-31T05:11:08Z 16721 TID-g97zs WARN: /home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `const_get'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `block in constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `inject'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-3.1.2/lib/sidekiq/processor.rb:46:in `process'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `public_send'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `dispatch'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:122:in `dispatch'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/actor.rb:322:in `block in handle_message'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/actor.rb:416:in `block in task'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:55:in `block in initialize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/tasks/task_fiber.rb:13:in `block in create'
2014-05-31T05:11:08Z 16721 TID-g97zs WARN: {"retry"=>true, "queue"=>"default", "class"=>"HttpreqWorker", "args"=>[1], "jid"=>"a7d9b8d8a1290ac1877e1eca", "enqueued_at"=>1401502462.4630978, "error_message"=>"Couldn't find Site with id=1", "error_class"=>"ActiveRecord::RecordNotFound", "failed_at"=>1401502462.4677737, "retry_count"=>8, "retried_at"=>1401507762.8017237}
2014-05-31T05:11:08Z 16721 TID-g97zs WARN: uninitialized constant HttpreqWorker
2014-05-31T05:11:08Z 16721 TID-g97zs WARN: /home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `const_get'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `block in constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `inject'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-3.1.2/lib/sidekiq/processor.rb:46:in `process'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `public_send'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `dispatch'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:122:in `dispatch'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/actor.rb:322:in `block in handle_message'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/actor.rb:416:in `block in task'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:55:in `block in initialize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/tasks/task_fiber.rb:13:in `block in create'
2014-05-31T05:11:08Z 16721 TID-knus4 WARN: {"retry"=>true, "queue"=>"default", "class"=>"HttpreqWorker", "args"=>[1], "jid"=>"ed7028f67d0aeaf3fdfa37ae", "enqueued_at"=>1401502391.916175, "error_message"=>"Couldn't find Site with id=1", "error_class"=>"ActiveRecord::RecordNotFound", "failed_at"=>1401502391.9222357, "retry_count"=>8, "retried_at"=>1401507747.7996333}
2014-05-31T05:11:08Z 16721 TID-knus4 WARN: uninitialized constant HttpreqWorker
2014-05-31T05:11:08Z 16721 TID-knus4 WARN: /home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `const_get'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `block in constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `inject'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-3.1.2/lib/sidekiq/processor.rb:46:in `process'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `public_send'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `dispatch'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/calls.rb:122:in `dispatch'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/actor.rb:322:in `block in handle_message'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/actor.rb:416:in `block in task'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:55:in `block in initialize'
/home/nate/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.15.2/lib/celluloid/tasks/task_fiber.rb:13:in `block in create'
def self.import(file, user_id)
s = open_spreadsheet(file)
(1..s.last_row).each do |i|
row = s.row(i).first
row_split = row.split(";")
site = Site.create!(
host:"#{row_split[0]}", pr:"#{row_split[1]}", tf:"#{row_split[2]}", cf:"#{row_split[3]}",
da:"#{row_split[4]}", pa:"#{row_split[5]}", dmoztrust:"#{row_split[6]}",
dmozrank:"#{row_split[7]}", dmozpagerank:"#{row_split[8]}",dmozpagetrust:"#{row_split[9]}",
niche:"#{row_split[10]}", ahrefurlrank:"#{row_split[11]}", ahrefdomainrank:"#{row_split[12]}",
wp_user:"#{row_split[13]}", wp_pass:"#{row_split[14]}", user_id:"#{user_id}")
ReqsWorker.perform_async(site.id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment