Class: GreenDay::TaskSourceToFileWorker

Inherits:
Object
  • Object
show all
Defined in:
lib/green_day/task_source_to_file_worker.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_sources) ⇒ TaskSourceToFileWorker

Returns a new instance of TaskSourceToFileWorker.



11
12
13
# File 'lib/green_day/task_source_to_file_worker.rb', line 11

def initialize(task_sources)
  @task_sources = task_sources
end

Class Method Details

.run_threads(task_sources) ⇒ Object



7
8
9
# File 'lib/green_day/task_source_to_file_worker.rb', line 7

def self.run_threads(task_sources)
  new(task_sources).run_threads
end

Instance Method Details

#run_threadsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/green_day/task_source_to_file_worker.rb', line 15

def run_threads
  @task_sources.map.with_index do |task_source, i|
    # avoid 429 error
    sleep 1 if (i % 7).zero? && !i.zero?

    Thread.new do
      task = Task.new(task_source.name,
                      task_source.path,
                      task_source.contest_name)
      task.create_file
      task.create_spec_file
    end
  end
end