Class: Wayfarer::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/wayfarer/cli.rb,
lib/wayfarer/cli/route_printer.rb

Defined Under Namespace

Classes: RoutePrinter

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/wayfarer/cli.rb', line 5

def self.exit_on_failure?
  true
end

Instance Method Details

#enqueue(job, url) ⇒ Object



42
43
44
45
46
47
# File 'lib/wayfarer/cli.rb', line 42

def enqueue(job, url)
  load_environment

  job = job.camelize.constantize
  job.crawl(url, batch: options[:batch])
end

#execute(job, url) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/wayfarer/cli.rb', line 55

def execute(job, url)
  load_environment
  mock_redis

  job = job.camelize.constantize
  job.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new(min_threads: options[:min_threads],
                                                                 max_threads: options[:max_threads])
  scheduler = job.queue_adapter.instance_variable_get(:@scheduler)
  executor = scheduler.instance_variable_get(:@async_executor)

  job.crawl(url, batch: options.fetch(:batch))

  sleep(0.1) while executor.scheduled_task_count > executor.completed_task_count

  # Used in test suite to avoid pool recreation
  Wayfarer::Networking::Pool.instance.free unless options.fetch(:retain_pool)
end

#perform(job, url) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/wayfarer/cli.rb', line 31

def perform(job, url)
  load_environment
  mock_redis

  job = job.camelize.constantize
  task = Wayfarer::Task.new(url, options.fetch(:batch))
  job.new(task).perform_now
end

#route(job, url) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/wayfarer/cli.rb', line 18

def route(job, url)
  load_environment

  url = parsed_url(url)
  job = job.camelize.constantize
  route = job.route

  Wayfarer::CLI::RoutePrinter.print(route, url, format: options.fetch("format"))
end

#versionObject



10
11
12
# File 'lib/wayfarer/cli.rb', line 10

def version
  say Wayfarer::VERSION::STRING
end