Class: Autobuild::RakeTaskParallelism::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/autobuild/parallel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_server, finished_workers) ⇒ Worker

Returns a new instance of Worker.



271
272
273
274
275
276
277
278
279
280
281
# File 'lib/autobuild/parallel.rb', line 271

def initialize(job_server, finished_workers)
    @job_server = job_server
    @finished_workers = finished_workers
    @input = Queue.new
    @thread = Thread.new do
        loop do
            task = @input.pop
            do_task(task)
        end
    end
end

Instance Attribute Details

#job_serverObject (readonly)

Returns the value of attribute job_server.



269
270
271
# File 'lib/autobuild/parallel.rb', line 269

def job_server
  @job_server
end

Class Method Details

.execute_task(task) ⇒ Object



283
284
285
286
287
# File 'lib/autobuild/parallel.rb', line 283

def self.execute_task(task)
    task_args = Rake::TaskArguments.new(task.arg_names, [])
    task.instance_variable_set(:@already_invoked, true)
    task.send(:execute, task_args)
end

Instance Method Details

#do_task(task) ⇒ Object



289
290
291
292
293
294
295
296
297
298
299
# File 'lib/autobuild/parallel.rb', line 289

def do_task(task)
    @last_error = nil
    Worker.execute_task(task)
    @last_finished_task = task
rescue ::Exception => e
    @last_finished_task = task
    @last_error = e
ensure
    job_server.put
    @finished_workers.push(self)
end

#last_resultObject



301
302
303
# File 'lib/autobuild/parallel.rb', line 301

def last_result
    [@last_finished_task, @last_error]
end

#queue(task) ⇒ Object



305
306
307
# File 'lib/autobuild/parallel.rb', line 305

def queue(task)
    @input.push(task)
end