Sha256: 82ece72cd21d4f00effa43470ee05ee1cc946974280a3034134f4ef358911fe5

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

module AnswersEngine
  module Client
    class ScraperJob < AnswersEngine::Client::Base
      def all(scraper_name, opts={})
        self.class.get("/scrapers/#{scraper_name}/jobs", @options)
      end

      def create(scraper_name, opts={})
        body = {}
        body[:standard_worker_count] = opts[:workers] if opts[:workers]
        body[:browser_worker_count] = opts[:browsers] if opts[:browsers]
        body[:proxy_type] = opts[:proxy_type] if opts[:proxy_type]
        @options.merge!({body: body.to_json})
        self.class.post("/scrapers/#{scraper_name}/jobs", @options)
      end

      def find(scraper_name)
        self.class.get("/scrapers/#{scraper_name}/current_job", @options)
      end

      def update(scraper_name, opts={})
        body = {}
        body[:status] = opts[:status] if opts[:status]
        body[:standard_worker_count] = opts[:workers] if opts[:workers]
        body[:browser_worker_count] = opts[:browsers] if opts[:browsers]
        body[:proxy_type] = opts[:proxy_type] if opts[:proxy_type]
        @options.merge!({body: body.to_json})

        self.class.put("/scrapers/#{scraper_name}/current_job", @options)
      end

      def cancel(scraper_name, opts={})
        opts[:status] = 'cancelled'
        update(scraper_name, opts)
      end

      def resume(scraper_name, opts={})
        opts[:status] = 'active'
        update(scraper_name, opts)
      end

      def pause(scraper_name, opts={})
        opts[:status] = 'paused'
        update(scraper_name, opts)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
answersengine-0.4.1 lib/answersengine/client/scraper_job.rb
answersengine-0.4.0 lib/answersengine/client/scraper_job.rb
answersengine-0.3.3 lib/answersengine/client/scraper_job.rb
answersengine-0.3.2 lib/answersengine/client/scraper_job.rb
answersengine-0.3.1 lib/answersengine/client/scraper_job.rb
answersengine-0.3.0 lib/answersengine/client/scraper_job.rb
answersengine-0.2.33 lib/answersengine/client/scraper_job.rb