Class: Schlepper::Task

Inherits:
Object
  • Object
show all
Includes:
AbstractMethodHelper
Defined in:
lib/schlepper/task.rb

Overview

Tasks live in your rails app under /script/tasks. They have the same filename pattern as rails migrations, time stamp_class_name.rb A functional generator is provided using ‘rails generate schlepper:task name_of_task`

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AbstractMethodHelper

#abstract_method?, included

Class Method Details

.childrenObject



10
11
12
# File 'lib/schlepper/task.rb', line 10

def self.children
  @children
end

.inherited(obj) ⇒ Object



14
15
16
17
# File 'lib/schlepper/task.rb', line 14

def self.inherited obj
  super
  children.push obj
end

Instance Method Details

#controls_transaction?Boolean

Signals to the task runner that this task will control its own transaction. When true the task runner will not open a transaction. Use with caution.

Returns:

  • (Boolean)


30
31
32
# File 'lib/schlepper/task.rb', line 30

def controls_transaction?
  false
end

#descriptionString

This method is abstract.

Returns Short note on the intent of this script.

Returns:

  • (String)

    Short note on the intent of this script



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

abstract def description
end

#ownerString

This method is abstract.

Returns Name of the person or people who have ownership of the script.

Returns:

  • (String)

    Name of the person or people who have ownership of the script



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

abstract def owner
end

#runBool

This method is abstract.

This is the entry point for your script. The full Rails stack is available. Return true if it was successful, false if not. If not successful, set @failure_message to something meaningful. Runs that return false will not be marked as run and will be continue to be run in subsequent batch runs

Returns:

  • (Bool)

    Success or failure



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

abstract def run
end

#version_numberFixnum

Returns The version number of the current class.

Returns:

  • (Fixnum)

    The version number of the current class



20
21
22
23
24
# File 'lib/schlepper/task.rb', line 20

def version_number
  # We have to find the actual file where the class is defined which is the reason for
  # the method source location weirdness
  @version_number ||= File.basename(method(:run).source_location.first).scan(/\A(\d{10,})/).first.first
end