Class: DeployPin::Task

Inherits:
Object
  • Object
show all
Extended by:
ParallelWrapper
Includes:
ParallelWrapper
Defined in:
lib/deploy_pin/task.rb

Constant Summary

Constants included from ParallelWrapper

ParallelWrapper::PARALLEL_PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ParallelWrapper

method_missing, respond_to_missing?

Constructor Details

#initialize(file) ⇒ Task

Returns a new instance of Task.



16
17
18
19
20
21
22
23
24
# File 'lib/deploy_pin/task.rb', line 16

def initialize(file)
  @file = file
  @uuid = nil
  @group = nil
  @title = ''
  @script = ''
  @explicit_timeout = false
  @parallel = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DeployPin::ParallelWrapper

Instance Attribute Details

#explicit_timeoutObject (readonly)

Returns the value of attribute explicit_timeout.



9
10
11
# File 'lib/deploy_pin/task.rb', line 9

def explicit_timeout
  @explicit_timeout
end

#fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/deploy_pin/task.rb', line 9

def file
  @file
end

#groupObject (readonly)

Returns the value of attribute group.



9
10
11
# File 'lib/deploy_pin/task.rb', line 9

def group
  @group
end

#scriptObject (readonly)

Returns the value of attribute script.



9
10
11
# File 'lib/deploy_pin/task.rb', line 9

def script
  @script
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/deploy_pin/task.rb', line 9

def title
  @title
end

#uuidObject (readonly)

Returns the value of attribute uuid.



9
10
11
# File 'lib/deploy_pin/task.rb', line 9

def uuid
  @uuid
end

Instance Method Details

#detailsObject



65
66
67
68
69
70
71
# File 'lib/deploy_pin/task.rb', line 65

def details
  {
    uuid: uuid,
    group: group,
    title: title
  }
end

#done?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/deploy_pin/task.rb', line 36

def done?
  DeployPin::Record.where(uuid: uuid).exists?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
# File 'lib/deploy_pin/task.rb', line 73

def eql?(other)
  # same script & different uuid
  script == other.script && uuid != other.uuid
end

#explicit_timeout?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/deploy_pin/task.rb', line 40

def explicit_timeout?
  @explicit_timeout
end

#markObject



31
32
33
34
# File 'lib/deploy_pin/task.rb', line 31

def mark
  # store record in the DB
  DeployPin::Record.create(uuid: uuid)
end

#parallel?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/deploy_pin/task.rb', line 44

def parallel?
  @parallel
end

#parse_fileObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/deploy_pin/task.rb', line 48

def parse_file
  File.foreach(file) do |line|
    case line.strip
    when /\A# (\d+):(\w+)/
      @uuid = Regexp.last_match(1)
      @group = Regexp.last_match(2)
    when /\A# task_title:(.+)/
      @title = Regexp.last_match(1).strip
    when /\A[^#].*/
      @script += line

      @explicit_timeout = true if line =~ /Database.execute_with_timeout.*/
      @parallel = true if line =~ /[Pp]arallel.*/
    end
  end
end

#runObject



26
27
28
29
# File 'lib/deploy_pin/task.rb', line 26

def run
  # eval script
  eval(script)
end