Class: Wayfarer::CLI::Job

Inherits:
Base
  • Object
show all
Defined in:
lib/wayfarer/cli/job.rb

Instance Method Summary collapse

Methods inherited from Base

after_batch, after_batch_callbacks, crawl_later, discard_on, #retry_job, retry_on, run_after_batch_callbacks

Methods included from Middleware::Worker

included

Instance Method Details

#enqueue(job, url) ⇒ Object



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

def enqueue(job, url)
  load_environment
  mock_redis if options[:mock_redis]

  url = URI(url)
  job = job.classify.constantize
  job.crawl_later(url, batch: options[:batch])
end

#execute(job, url) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/wayfarer/cli/job.rb', line 40

def execute(job, url)
  load_environment
  mock_redis if options[:mock_redis]

  url = URI(url)
  job = job.classify.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_later(url, batch: options[:batch])

  sleep(1) while executor.scheduled_task_count > executor.completed_task_count
end

#perform(job, url) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/wayfarer/cli/job.rb', line 10

def perform(job, url)
  load_environment
  mock_redis if options[:mock_redis]

  url = URI(url)
  job = job.classify.constantize.new
  task = Wayfarer::Task.new(url, "tmp")
  job.arguments.push(task)
  job.perform(task)
  GC.new(job).run
end