Module: Cadence

Defined in:
lib/cadence/thread_pool.rb,
lib/cadence.rb,
lib/cadence/json.rb,
lib/cadence/uuid.rb,
lib/cadence/types.rb,
lib/cadence/utils.rb,
lib/cadence/client.rb,
lib/cadence/errors.rb,
lib/cadence/worker.rb,
lib/cadence/metrics.rb,
lib/cadence/testing.rb,
lib/cadence/version.rb,
lib/cadence/activity.rb,
lib/cadence/metadata.rb,
lib/cadence/workflow.rb,
lib/cadence/saga/saga.rb,
lib/cadence/saga/result.rb,
lib/cadence/retry_policy.rb,
lib/cadence/saga/concern.rb,
lib/cadence/client/errors.rb,
lib/cadence/configuration.rb,
lib/cadence/metadata/base.rb,
lib/cadence/concerns/typed.rb,
lib/cadence/activity/poller.rb,
lib/cadence/workflow/future.rb,
lib/cadence/workflow/poller.rb,
lib/cadence/activity/context.rb,
lib/cadence/middleware/chain.rb,
lib/cadence/middleware/entry.rb,
lib/cadence/workflow/context.rb,
lib/cadence/workflow/history.rb,
lib/cadence/executable_lookup.rb,
lib/cadence/execution_options.rb,
lib/cadence/metadata/activity.rb,
lib/cadence/metadata/decision.rb,
lib/cadence/metadata/workflow.rb,
lib/cadence/workflow/decision.rb,
lib/cadence/workflow/executor.rb,
lib/cadence/concerns/executable.rb,
lib/cadence/workflow/dispatcher.rb,
lib/cadence/workflow/serializer.rb,
lib/cadence/activity/async_token.rb,
lib/cadence/client/thrift_client.rb,
lib/cadence/metrics_adapters/log.rb,
lib/cadence/thread_local_context.rb,
lib/cadence/metrics_adapters/null.rb,
lib/cadence/workflow/history/event.rb,
lib/cadence/workflow/state_manager.rb,
lib/cadence/activity/task_processor.rb,
lib/cadence/testing/future_registry.rb,
lib/cadence/workflow/execution_info.rb,
lib/cadence/workflow/history/window.rb,
lib/cadence/testing/cadence_override.rb,
lib/cadence/workflow/serializer/base.rb,
lib/cadence/testing/workflow_override.rb,
lib/cadence/testing/workflow_execution.rb,
lib/cadence/workflow/convenience_methods.rb,
lib/cadence/workflow/replay_aware_logger.rb,
lib/cadence/workflow/history/event_target.rb,
lib/cadence/testing/local_activity_context.rb,
lib/cadence/testing/local_workflow_context.rb,
lib/cadence/workflow/decision_state_machine.rb,
lib/cadence/workflow/serializer/start_timer.rb,
lib/cadence/workflow/decision_task_processor.rb,
lib/cadence/workflow/serializer/cancel_timer.rb,
lib/cadence/workflow/serializer/fail_workflow.rb,
lib/cadence/workflow/serializer/record_marker.rb,
lib/cadence/activity/workflow_convenience_methods.rb,
lib/cadence/workflow/serializer/complete_workflow.rb,
lib/cadence/workflow/serializer/schedule_activity.rb,
lib/cadence/workflow/serializer/start_child_workflow.rb,
lib/cadence/workflow/serializer/request_activity_cancellation.rb

Overview

Provides context for Cadence::Activity::WorkflowConvenienceMethods

Defined Under Namespace

Modules: Client, Concerns, JSON, Metadata, MetricsAdapters, Middleware, Saga, Testing, ThreadLocalContext, Types, UUID, Utils Classes: Activity, ActivityException, ClientError, Configuration, Error, ExecutableLookup, ExecutionOptions, InternalError, Metrics, NonDeterministicWorkflowError, RetryPolicy, ThreadPool, TimeoutError, Worker, Workflow

Constant Summary collapse

VERSION =
'0.1.0'.freeze

Class Method Summary collapse

Class Method Details

.complete_activity(async_token, result = nil) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cadence.rb', line 110

def complete_activity(async_token, result = nil)
  details = Activity::AsyncToken.decode(async_token)

  client.respond_activity_task_completed_by_id(
    domain: details.domain,
    activity_id: details.activity_id,
    workflow_id: details.workflow_id,
    run_id: details.run_id,
    result: result
  )
end

.configurationObject



139
140
141
# File 'lib/cadence.rb', line 139

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



135
136
137
# File 'lib/cadence.rb', line 135

def configure(&block)
  yield configuration
end

.fail_activity(async_token, error) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/cadence.rb', line 122

def fail_activity(async_token, error)
  details = Activity::AsyncToken.decode(async_token)

  client.respond_activity_task_failed_by_id(
    domain: details.domain,
    activity_id: details.activity_id,
    workflow_id: details.workflow_id,
    run_id: details.run_id,
    reason: error.class.name,
    details: error.message
  )
end

.fetch_workflow_execution_info(domain, workflow_id, run_id) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'lib/cadence.rb', line 100

def fetch_workflow_execution_info(domain, workflow_id, run_id)
  response = client.describe_workflow_execution(
    domain: domain,
    workflow_id: workflow_id,
    run_id: run_id
  )

  Workflow::ExecutionInfo.generate_from(response.workflowExecutionInfo)
end

.get_workflow_history(domain:, workflow_id:, run_id:) ⇒ Object



151
152
153
154
155
156
157
158
# File 'lib/cadence.rb', line 151

def get_workflow_history(domain:, workflow_id:, run_id:)
  history_response = client.get_workflow_execution_history(
    domain: domain,
    workflow_id: workflow_id,
    run_id: run_id
  )
  Workflow::History.new(history_response.history.events)
end

.loggerObject



143
144
145
# File 'lib/cadence.rb', line 143

def logger
  configuration.logger
end

.metricsObject



147
148
149
# File 'lib/cadence.rb', line 147

def metrics
  @metrics ||= Metrics.new(configuration.metrics_adapter)
end

.register_domain(name, description = nil) ⇒ Object



59
60
61
62
63
# File 'lib/cadence.rb', line 59

def register_domain(name, description = nil)
  client.register_domain(name: name, description: description)
rescue CadenceThrift::DomainAlreadyExistsError
  nil
end

.reset_workflow(domain, workflow_id, run_id, decision_task_id: nil, reason: 'manual reset') ⇒ Object

Raises:



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cadence.rb', line 75

def reset_workflow(domain, workflow_id, run_id, decision_task_id: nil, reason: 'manual reset')
  decision_task_id ||= get_last_completed_decision_task(domain, workflow_id, run_id)
  raise Error, 'Could not find a completed decision task event' unless decision_task_id

  response = client.reset_workflow_execution(
    domain: domain,
    workflow_id: workflow_id,
    run_id: run_id,
    reason: reason,
    decision_task_event_id: decision_task_id
  )

  response.runId
end

.schedule_workflow(workflow, cron_schedule, *input, **args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cadence.rb', line 36

def schedule_workflow(workflow, cron_schedule, *input, **args)
  options = args.delete(:options) || {}
  input << args unless args.empty?

  execution_options = ExecutionOptions.new(workflow, options)
  workflow_id = options[:workflow_id] || SecureRandom.uuid

  response = client.start_workflow_execution(
    domain: execution_options.domain,
    workflow_id: workflow_id,
    workflow_name: execution_options.name,
    task_list: execution_options.task_list,
    input: input,
    execution_timeout: execution_options.timeouts[:execution],
    task_timeout: execution_options.timeouts[:task],
    workflow_id_reuse_policy: options[:workflow_id_reuse_policy],
    headers: execution_options.headers,
    cron_schedule: cron_schedule
  )

  response.runId
end

.signal_workflow(workflow, signal, workflow_id, run_id, input = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/cadence.rb', line 65

def signal_workflow(workflow, signal, workflow_id, run_id, input = nil)
  client.signal_workflow_execution(
    domain: workflow.domain, # TODO: allow passing domain instead
    workflow_id: workflow_id,
    run_id: run_id,
    signal: signal,
    input: input
  )
end

.start_workflow(workflow, *input, **args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cadence.rb', line 14

def start_workflow(workflow, *input, **args)
  options = args.delete(:options) || {}
  input << args unless args.empty?

  execution_options = ExecutionOptions.new(workflow, options)
  workflow_id = options[:workflow_id] || SecureRandom.uuid

  response = client.start_workflow_execution(
    domain: execution_options.domain,
    workflow_id: workflow_id,
    workflow_name: execution_options.name,
    task_list: execution_options.task_list,
    input: input,
    execution_timeout: execution_options.timeouts[:execution],
    task_timeout: execution_options.timeouts[:task],
    workflow_id_reuse_policy: options[:workflow_id_reuse_policy],
    headers: execution_options.headers
  )

  response.runId
end

.terminate_workflow(domain, workflow_id, run_id, reason: 'manual termination', details: nil) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/cadence.rb', line 90

def terminate_workflow(domain, workflow_id, run_id, reason: 'manual termination', details: nil)
  client.terminate_workflow_execution(
    domain: domain,
    workflow_id: workflow_id,
    run_id: run_id,
    reason: reason,
    details: details
  )
end