Class: Henry::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/henry/task.rb,
lib/henry/task/rake_task.rb,
lib/henry/task/rspec_task.rb,
lib/henry/task/cucumber_task.rb,
lib/henry/task/minitest_task.rb

Overview

Henry Task

Direct Known Subclasses

RakeTask

Defined Under Namespace

Classes: CucumberTask, MiniTestTask, RakeTask, RspecTask

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, data) ⇒ Task

Initialize the Task with the given name and data.



22
23
24
25
26
27
28
# File 'lib/henry/task.rb', line 22

def initialize(name, data)
  self.data = OpenStruct.new(data)
  self.enabled = true
  self.execution.task_name = name
  self.name = name
  self.timeout = self.data.timeout || 18000 #The given timeout (in seconds) or 5 hours
end

Instance Attribute Details

#dataObject

Accessors for name, data and enabled



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

def data
  @data
end

#enabledObject

Accessors for name, data and enabled



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

def enabled
  @enabled
end

#nameObject

Accessors for name, data and enabled



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

def name
  @name
end

#timeoutObject

Accessors for name, data and enabled



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

def timeout
  @timeout
end

Class Method Details

.create(name, data) ⇒ Henry::Task

Note:

Factory to create X Task instances.

Returns an instance of the target Task class.

Parameters:

  • name (String)

    the name of the task.

  • data (Hash)

    task attrbutes (class_name MUST be included).

Returns:



17
18
19
# File 'lib/henry/task.rb', line 17

def self.create(name, data)
  return Kernel.eval(data['class_name']).new(name, data)
end

Instance Method Details

#after_executeObject

Code to be run justafter the execution



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

def after_execute
  LoggerService.stop
end

#before_executeObject

Code to be run just before the execution



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

def before_execute
  LoggerService.start(self.logger)
end

#configure(params, extended_context = {}) ⇒ Object

Nothing to be done here… The Task configuration code should be defined under this method on the specific Task class.



106
107
# File 'lib/henry/task.rb', line 106

def configure(params, extended_context={})
end

#disable!Object

Makes the Task disabled



95
96
97
# File 'lib/henry/task.rb', line 95

def disable!
  self.enabled = false
end

#disabled?True, False

Returns true whenever the Task is disabled.

Returns:

  • (True, False)


85
86
87
# File 'lib/henry/task.rb', line 85

def disabled?
  !self.enabled?
end

#enable!Object

Makes the Task enabled



90
91
92
# File 'lib/henry/task.rb', line 90

def enable!
  self.enabled = true
end

#enabled?True, False

Returns true whenever the Task is enabled.

Returns:

  • (True, False)


78
79
80
# File 'lib/henry/task.rb', line 78

def enabled?
  self.enabled
end

#executeObject

The execution code should be defined under this method on the specific Task class.



100
101
102
# File 'lib/henry/task.rb', line 100

def execute
  abort "Your task class ('#{self.class}' may be?) MUST define this method with its execution logic."
end

#executionExecution

Returns the Task Execution.

Returns:



64
65
66
# File 'lib/henry/task.rb', line 64

def execution
  @execution ||= Execution.new
end

#export_config(config) ⇒ Object

Exports the Task config to the ENV.

Parameters:

  • params (Hash)

    the Task config to be exported.



57
58
59
# File 'lib/henry/task.rb', line 57

def export_config(config)
  Henry::Config.export!(config)
end

#export_params(params) ⇒ Object

Exports the Task params to the ENV.

Parameters:

  • params (Hash)

    the Task params to be exported.



50
51
52
# File 'lib/henry/task.rb', line 50

def export_params(params)
  Input.export!(params)
end

#loggerLogger

Returns the Task Logger.

Returns:



71
72
73
# File 'lib/henry/task.rb', line 71

def logger
  @logger ||= Logger.new
end

#reportHash

Returns the json ready hash report of the task execution.

Returns:

  • (Hash)


43
44
45
# File 'lib/henry/task.rb', line 43

def report
  self.execution.report
end