Module: Ntswf::Base

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

Instance Method Summary collapse

Instance Method Details

#activity_nameObject



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

def activity_name
  "master-activity"
end

#activity_task_listsObject



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

def activity_task_lists
  @config.activity_task_lists
end

#activity_typeObject



118
119
120
# File 'lib/ntswf/base.rb', line 118

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 (deprecated, should use swf option)

  • :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_id_prefix (String) — default: value of :unit

    Workflow ID prefix (see Client#start_execution‘s :execution_id for allowed values)

  • :execution_version (Numeric)

    Value allowing clients to reject future execution versions

  • :identity_suffix (String)

    When polling for a task, the suffix will be appended to the (default) identity (<hostname>:<pid>), delimited by a “:”. Allows to distinguish worker activity on different hosts with identical hostnames.

  • :isolation_file (String)

    Development/test option. A random ID is stored at the given path, and prepended to task list names and execution IDs.

  • :pidfile (String)

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

  • :secret_access_key (String)

    AWS credential (deprecated, should use swf option)

  • :subprocess_retries (Numeric) — default: 0
  • :swf (AWS::SimpleWorkflow)

    AWS simple workflow object (created e.g. with AWS::SimpleWorkflow.new)

  • :unit (String)

    This worker/client’s activity task list key

Raises:



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

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

#decision_task_listObject



80
81
82
83
# File 'lib/ntswf/base.rb', line 80

def decision_task_list
  @config.decision_task_list or raise Errors::InvalidArgument.new(
      "Missing decision task list configuration")
end

#default_unitObject



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

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

#domainObject



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

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

#execution_id_prefixObject



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

def execution_id_prefix
  "#{isolation_id}#{@config.execution_id_prefix || default_unit}"
end

#execution_versionObject



93
94
95
# File 'lib/ntswf/base.rb', line 93

def execution_version
  @config.execution_version
end

#notify(message, params) ⇒ Object



108
109
110
111
# File 'lib/ntswf/base.rb', line 108

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



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

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:



101
102
103
104
105
106
# File 'lib/ntswf/base.rb', line 101

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



114
115
116
# File 'lib/ntswf/base.rb', line 114

def separator
  ";"
end

#swfAWS::SimpleWorkflow

Returns:

  • (AWS::SimpleWorkflow)


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

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

#workflow_nameObject



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

def workflow_name
  "master-workflow"
end

#workflow_versionObject



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

def workflow_version
  "v1"
end