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



49
50
51
52
53
54
# File 'lib/wayfarer/cli.rb', line 49

def enqueue(job, url)
  load_environment

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

#execute(job, url) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/wayfarer/cli.rb', line 62

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



38
39
40
41
42
43
44
45
# File 'lib/wayfarer/cli.rb', line 38

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



25
26
27
28
29
30
31
32
33
# File 'lib/wayfarer/cli.rb', line 25

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