This repository was archived by the owner on Sep 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Basic Usage
Irfan Ahmed edited this page Jan 31, 2018
·
1 revision
##Basic Usage Build any service with the track! Add as many tracks as you want. tracks will be loaded sequentially. You can control success and failure state of any specific step.
Consider the following class:
class AnotherOperation < Clomp::Operation
track :track_from_another_operation
def track_from_another_operation(options)
options[:hello_from_another_operation] = true
end
end
class SingingOperation < Clomp::Operation
# Configure your operation for common tracks,
# configuration can be overridden from individual tracks
setup do |config|
config.fail_fast = true
config.optional = true
end
# this block only executes on failure step!
# pass options to receive the operation states!
add_track :get_lyrics do |options|
# we call this a failure state based block!
options[:do_some_thing] = 10
end
add_track :get_instruments_ready
add_track :start_signing
# We can now share specific step from
# outsider operation
share :track_from_another_operation, from: AnotherOperation # Or 'AnotherOperation'
finally :receive_price #final step, wont execute after this step!
def get_instruments_ready(options, params: , **)
# do anything!
end
def get_lyrics(options, params: , **)
params[:singer_name] = 'James' #mutate
end
def start_signing(options)
puts options[:params]
end
def receive_price(options)
puts "I am honored for this awesome price!"
end
end@result = SingingOperation[singer_name: 'Base Baba']
@result.success? # => true
@result.failure? # => falseTrace the steps:
@result = SingingOperation[singer_name: 'Base Baba']
@result.executed_tracks
"first_track:track:success --> track_from_another_operation:track:success --> call_something:track:success"
@result.to_s
"Clomp::Result > Successful: first_track:track:success --> track_from_another_operation:track:success --> call_something:track:success"You can set custom step name(s), custom fail, pass flow configuration globally and operation wise!
Clomp::Configuration.setup do |config|
# You can set as many step name as you want
config.custom_step_names =+ [:my_own_step_name]
end