Module: Ntswf::Base

Included in:
Client, Utils, Worker
Defined in:
lib/ntswf/base.rb

Instance Method Summary collapse

Instance Method Details

#activity_task_listObject



67
68
69
# File 'lib/ntswf/base.rb', line 67

def activity_task_list
  activity_task_lists[default_unit] or raise "Missing activity task list configuration"
end

#activity_task_listsObject



59
60
61
# File 'lib/ntswf/base.rb', line 59

def activity_task_lists
  @config.activity_task_lists
end

#activity_typeObject



100
101
102
# File 'lib/ntswf/base.rb', line 100

def activity_type
  @activity_type ||= domain.activity_types[activity_name, workflow_version]
end

#configure(config) ⇒ Object

Parameters:

  • config (Hash)

    A configuration with the following keys:

Options Hash (config):

  • :access_key_id (String)

    AWS credential

  • :activity_task_lists (Hash)

    The task list names for activities as hash (see also :unit)

  • :decision_task_list (String)

    The task list name for decisions

  • :domain (String)

    The SWF domain name

  • :execution_version (Numeric)

    Value allowing clients to reject future execution versions

  • :pidfile (String)

    A path receiving the current PID for looping methods. Causes exit, if overwritten by another process. See Worker#in_subprocess

  • :subprocess_retries (Numeric) — default: 0
  • :secret_access_key (String)

    AWS credential

  • :task_list_suffix_file (String)

    Development option. A random ID is stored at the given path, and appended to all task list names.

  • :unit (String)

    This worker/client’s activity task list key

Raises:

  • If a task list name is invalid



25
26
27
28
29
# File 'lib/ntswf/base.rb', line 25

def configure(config)
  @config = OpenStruct.new(config)
  autocomplete_task_list_names!
  raise_if_invalid_task_list
end

#decision_task_listObject



63
64
65
# File 'lib/ntswf/base.rb', line 63

def decision_task_list
  @config.decision_task_list or raise "Missing decision task list configuration"
end

#default_unitObject



71
72
73
# File 'lib/ntswf/base.rb', line 71

def default_unit
  @default_unit ||= @config.unit.to_s
end

#domainObject



55
56
57
# File 'lib/ntswf/base.rb', line 55

def domain
  @domain ||= swf.domains[@config.domain]
end

#execution_versionObject



75
76
77
# File 'lib/ntswf/base.rb', line 75

def execution_version
  @config.execution_version
end

#notify(message, params) ⇒ Object



90
91
92
93
# File 'lib/ntswf/base.rb', line 90

def notify(message, params)
  log("#{message.message}\n  #{message.backtrace.join("\n  ")}") if message.kind_of? Exception
  @notify_callback.call(message: message, params: params) if @notify_callback
end

#on_notify(proc = nil) {|error| ... } ⇒ Object

Configure a proc or block to be called on handled errors

Parameters:

  • proc (Proc) (defaults to: nil)

    The callback

Yield Parameters:

  • error (Hash)

    Description of the error:

    :message

    The error message or the exception

    :params

    Error details



37
38
39
# File 'lib/ntswf/base.rb', line 37

def on_notify(proc = nil, &block)
  @notify_callback = proc || block
end

#parse_input(input) ⇒ Hash

Parse the options stored in a task’s input value

Parameters:

  • input (String)

    A task’s input

Returns:

  • (Hash)

    Input, converted back from JSON

See Also:



83
84
85
86
87
88
# File 'lib/ntswf/base.rb', line 83

def parse_input(input)
  options, legacy_params = JSON.parse(input)
  options = {"name" => options} unless options.kind_of? Hash
  options.merge!("params" => legacy_params) if legacy_params
  options
end

#separatorString

Returns separator for composite workflow_id.

Returns:

  • (String)

    separator for composite workflow_id



96
97
98
# File 'lib/ntswf/base.rb', line 96

def separator
  ";"
end

#swfAWS::SimpleWorkflow

Returns:

  • (AWS::SimpleWorkflow)


42
43
44
45
# File 'lib/ntswf/base.rb', line 42

def swf
  @swf ||= AWS::SimpleWorkflow.new(access_key_id: @config.access_key_id,
      secret_access_key: @config.secret_access_key, use_ssl: true)
end

#workflow_nameObject



47
48
49
# File 'lib/ntswf/base.rb', line 47

def workflow_name
  "#{default_unit}-workflow"
end

#workflow_versionObject



51
52
53
# File 'lib/ntswf/base.rb', line 51

def workflow_version
  "v1"
end