Module: JobFactory

Defined in:
lib/job_factory.rb

Overview

This Module has convenient functions to instantiate Job objects.

Constant Summary collapse

@@mutex =
Mutex.new
@@seqnum =
0

Class Method Summary collapse

Class Method Details

.generate_local_command_job(command, job_group) ⇒ LocalJob

Generates a LocalJob running a command.

Parameters:

  • command (String)

    The command to run.

  • job_group (String)

    The job group of the job.

Returns:


16
17
18
19
20
# File 'lib/job_factory.rb', line 16

def JobFactory.generate_local_command_job(command, job_group)
  LocalJob.new("locally running #{command}", job_group, lambda do
    system command
  end)
end

.generate_remote_command_job(command, job_group, host_group, result_transformer) ⇒ RemoteJob

Generates a RemoteJob running a command.

Parameters:

  • command (String)

    The command to run.

  • job_group (String)

    The job group of the job.

  • host_group (String)

    The host group of the job.

Returns:


27
28
29
30
31
# File 'lib/job_factory.rb', line 27

def JobFactory.generate_remote_command_job(command, job_group, host_group,
                                           result_transformer)
  RemoteJob.new("remotely running #{command}", job_group, host_group,
                command, result_transformer)
end

.generate_remote_compile_and_eval_job(job_group_meta, job_group_compile, job_group_eval, host_group_compile, host_group_eval, folder_compile, folder_eval, cmdlines_compile, cmdlines_eval, result_transformer_compile, result_transformer_eval, result_transformer_result) ⇒ RemoteJob

Generates a meta job containing 2 remote job in series.

Parameters:

  • job_group_meta (String)

    For the MetaJob: The job group of the job.

  • job_group_compile (String)

    For the first RemoteJob: The job group of the job.

  • job_group_eval (String)

    For the second RemoteJob: The job group of the job.

  • host_group_compile (String)

    For the first RemoteJob: The host group of the job.

  • host_group_eval (String)

    For the second RemoteJob: The host group of the job.

  • folder_compile (String)

    For the first RemoteJob: The folder on the remote host to contain the randomly named folder that is the working directory of the command.

  • folder_eval (String)

    For the second RemoteJob: The folder on the remote host to contain the randomly named folder that is the working directory of the command.

  • cmdline_compile (String)

    For the first RemoteJob: The command to run.

  • cmdline_eval (String)

    For the second RemoteJob: The command to run.

  • result_transformer_compile (String)

    For the first RemoteJob: The result transformer to use.

  • result_transformer_eval (String)

    For the second RemoteJob: The result transformer to use.

Returns:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/job_factory.rb', line 78

def JobFactory.generate_remote_compile_and_eval_job(job_group_meta,
                                                    job_group_compile,
                                                    job_group_eval,
                                                    host_group_compile,
                                                    host_group_eval,
                                                    folder_compile,
                                                    folder_eval,
                                                    cmdlines_compile,
                                                    cmdlines_eval,
                                                    result_transformer_compile,
                                                    result_transformer_eval,
                                                    result_transformer_result)
  compile_jobs = cmdlines_compile.map do |cmdline|
    generate_remote_job_in_dir job_group_compile, host_group_compile,
      folder_compile, cmdline, result_transformer_compile
  end
  eval_jobs = cmdlines_eval.map do |cmdline|
    generate_remote_job_in_dir job_group_eval, host_group_eval,
      folder_eval, cmdline, result_transformer_eval
  end

  MetaJob.new "remote compilation and evaluation job", job_group_meta,
    (compile_jobs.zip eval_jobs), result_transformer_result
end

.generate_remote_job_in_dir(job_group, host_group, folder, cmdline, result_transformer, random_dir = true) ⇒ RemoteJob

Generates a RemoteJob that will be run in a randomly named folder within a certain folder.

The random folder name is guranteed to be unique for the runtime of the programm, but not across restarts.

Parameters:

  • job_group (String)

    The job group of the job.

  • host_group (String)

    The host group of the job.

  • folder (String)

    The folder on the remote host to contain the randomly named folder that is the working directory of the command.

  • cmdline (String)

    The command to run.

Returns:


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/job_factory.rb', line 43

def JobFactory.generate_remote_job_in_dir(job_group, host_group, folder,
                                          cmdline, result_transformer,
                                          random_dir = true)
  if random_dir then
    seqnum = 0
    # generate a new name for the output_dir
    @@mutex.synchronize {
      seqnum = @@seqnum
      @@seqnum += 1
    }
    dirname = folder + "/jobdir_" + seqnum.to_s + "_" + Time.new.to_i.to_s
  else
    dirname = folder
  end

  # build command
  command = "mkdir -p %s ; cd %s ; %s" % [dirname, dirname, cmdline]

  generate_remote_command_job command,
    job_group, host_group, result_transformer
end