Class: Apify::Scheduler::Unit
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Apify::Scheduler::Unit
- Defined in:
- app/models/apify/scheduler/unit.rb
Instance Method Summary collapse
Instance Method Details
#currently_working? ⇒ Boolean
11 12 13 |
# File 'app/models/apify/scheduler/unit.rb', line 11 def currently_working? Resque.working.map{ |w| w.job['payload']['args'].first }.include? self.id end |
#enqueue ⇒ Object
15 16 17 18 |
# File 'app/models/apify/scheduler/unit.rb', line 15 def enqueue history = histories.create Resque.enqueue(UnitPerformerJob, self.id, history.id) end |
#frequency ⇒ Object
41 42 43 |
# File 'app/models/apify/scheduler/unit.rb', line 41 def frequency frequency_quantity.send(frequency_period.name.pluralize) end |
#perform ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/apify/scheduler/unit.rb', line 20 def perform begin json = pattern server_query = ["processes=#{processes}", "delay=#{delay}", "apify_secret=#{server.api_key}"].join('&') server_crawler_url = [server.url.chomp('/'), '/crawler'].join server_url = [server_crawler_url, server_query].join('?') request_resource = RestClient::Resource.new( server_url, timeout: -1, open_timeout: -1 ) request = request_resource.post json, {:content_type => :json, :accept => :json} # TODO: record download attempts request = JSON.parse(request).to_json response_resource = RestClient::Resource.new( destination, timeout: -1, open_timeout: -1 ) response_resource.post request, {:content_type => :json, :accept => :json} #rescue ActiveRecord, JSON, RestClient, Parallel, Errno, Errno::EPIPE, Errno::PIPE rescue Exception => e { success: 0, message: e.}.to_json end end |