Module: Grably::Core::TaskExtensions::Jobs

Included in:
Grably::Core::TaskExtensions
Defined in:
lib/grably/core/task/jobs.rb

Overview

# Jobs

See Also:

  • Job

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/grably/core/task/jobs.rb', line 7

def method_missing(meth, *args, &block)
  job_class = find_job_class(meth.to_s)
  if job_class
    execute_job_with_args(args, job_class, meth)
  else
    super
  end
end

Instance Method Details

#execute_job_with_args(args, job_class, meth) ⇒ Object



16
17
18
19
20
# File 'lib/grably/core/task/jobs.rb', line 16

def execute_job_with_args(args, job_class, meth)
  working_dir = job_dir(task_dir, meth.to_s)
  FileUtils.mkdir_p(working_dir)
  job_class.new.run(self, working_dir, *args)
end

#job_dir(base_dir, job_name) ⇒ String

Create working directory for instantiated job inside task directory

Parameters:

  • base_dir (String)

    task working directory

  • job_name (String)

    Grably::Job call name

Returns:

  • (String)

    job working directory



26
27
28
29
30
31
32
33
34
35
# File 'lib/grably/core/task/jobs.rb', line 26

def job_dir(base_dir, job_name)
  # All this flow is working under assumption that all task jobs called
  # in same order. We store counter for each job in Task instance and
  # it updated throug all task live time. Each time task instance is
  # recreated we use frech (zero) counter
  counter = (jobs[job_name] || -1) + 1
  jobs[job_name] = counter
  name = [job_name, counter.to_s.rjust(3, '0')].join('-')
  File.join(base_dir, name)
end

#jobsObject



37
38
39
# File 'lib/grably/core/task/jobs.rb', line 37

def jobs
  @jobs ||= {}
end

#respond_to_missing?(meth, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/grably/core/task/jobs.rb', line 41

def respond_to_missing?(meth, include_private = false)
  find_job_class(meth) || super
end