Skip to content

Commit

Permalink
Removing client_actions from across the implementation and test code
Browse files Browse the repository at this point in the history
  • Loading branch information
neomatrix369 committed Oct 28, 2018
1 parent 8f0f131 commit 2ec5549
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 124 deletions.
15 changes: 0 additions & 15 deletions features/queue_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,6 @@ def as_implementation(call)
end
end

include TDL::ClientActions
CLIENT_ACTIONS = {
'publish' => publish,
'stop' => stop,
'publish and stop' => publish_and_stop
}

def as_action(actionName)
if CLIENT_ACTIONS.has_key?(actionName)
CLIENT_ACTIONS[actionName]
else
raise "Not a valid action reference: \"#{actionName}\""
end
end


When(/^I go live with the following processing rules:$/) do |table|
processing_rules = TDL::ProcessingRules.new
Expand Down
5 changes: 2 additions & 3 deletions lib/tdl/queue/abstractions/processing_rule.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module TDL
class ProcessingRule
attr_reader :user_implementation, :client_action
attr_reader :user_implementation

def initialize(user_implementation, client_action)
def initialize(user_implementation)
@user_implementation = user_implementation
@client_action = client_action
end
end
end
6 changes: 0 additions & 6 deletions lib/tdl/queue/abstractions/response/fatal_error_response.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
require 'tdl/queue/actions/stop_action'

module TDL
class FatalErrorResponse

def initialize(message)
@message = message
end

def client_action
StopAction.new
end

def audit_text
"error = #{@message}"
end
Expand Down
5 changes: 2 additions & 3 deletions lib/tdl/queue/abstractions/response/valid_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

module TDL
class ValidResponse
attr_reader :id, :result, :client_action
attr_reader :id, :result

def initialize(id, result, client_action)
def initialize(id, result)
@id = id
@result = result
@client_action = client_action
end

def to_h
Expand Down
20 changes: 0 additions & 20 deletions lib/tdl/queue/actions/client_actions.rb

This file was deleted.

17 changes: 0 additions & 17 deletions lib/tdl/queue/actions/publish_action.rb

This file was deleted.

16 changes: 0 additions & 16 deletions lib/tdl/queue/actions/publish_and_stop_action.rb

This file was deleted.

17 changes: 0 additions & 17 deletions lib/tdl/queue/actions/stop_action.rb

This file was deleted.

11 changes: 5 additions & 6 deletions lib/tdl/queue/processing_rules.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'tdl/queue/abstractions/processing_rule'
require 'tdl/queue/abstractions/response/fatal_error_response'
require 'tdl/queue/abstractions/response/valid_response'
require 'tdl/queue/actions/client_actions'

module TDL
class ProcessingRules
Expand All @@ -13,8 +12,8 @@ def initialize

# ~~~~ Builders

def add(method_name, user_implementation, client_action)
@rules[method_name] = ProcessingRule.new(user_implementation, client_action)
def add(method_name, user_implementation)
@rules[method_name] = ProcessingRule.new(user_implementation)
end

def on(method_name)
Expand All @@ -33,8 +32,8 @@ def call(user_implementation)
self
end

def then(client_action)
@instance.add(@method_name, @user_implementation, client_action)
def build()
@instance.add(@method_name, @user_implementation)
end
end

Expand All @@ -54,7 +53,7 @@ def get_response_for(request)
user_implementation = processing_rule.user_implementation
result = user_implementation.call(*request.params)

return ValidResponse.new(request.id, result, processing_rule.client_action)
return ValidResponse.new(request.id, result)
rescue Exception => e
message = '"user implementation raised exception"'
@logger.warn("#{message}, #{e.message}")
Expand Down
16 changes: 8 additions & 8 deletions lib/tdl/queue/queue_based_implementation_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ def process_next_request_from(remote_broker, request)
# Obtain response from user
response = @processing_rules.get_response_for(request)
@audit.log(response)

# Obtain action
client_action = response.client_action


# Act
client_action.after_response(remote_broker, request, response)
@audit.log(client_action)
@audit.end_line
client_action.prepare_for_next_request(remote_broker)
if response = fatal_error_response
@audit.end_line
remote_broker.close
return
end

remote_broker.respond_to(request, response)
end

end
Expand Down
7 changes: 3 additions & 4 deletions lib/tdl/queue/queue_based_implementation_runner_builder.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'tdl/queue/queue_based_implementation_runner'
require 'tdl/queue/actions/client_actions'

module TDL

Expand All @@ -14,11 +13,11 @@ def set_config(config)
self
end

def with_solution_for(method_name, user_implementation, action = ClientActions.publish)
def with_solution_for(method_name, user_implementation)
@deploy_processing_rules
.on(method_name)
.call(user_implementation)
.then(action)
.build()
self
end

Expand All @@ -31,7 +30,7 @@ def create
deploy_processing_rules
.on('display_description')
.call(-> (*params) {'OK'})
.then(ClientActions.publish)
.build()
deploy_processing_rules
end

Expand Down
13 changes: 4 additions & 9 deletions lib/tdl/runner/runner_action.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
require 'tdl/queue/actions/client_actions'

include TDL::ClientActions

class RunnerAction
attr_reader :short_name, :name, :client_action
attr_reader :short_name, :name

def initialize(short_name, name, client_action)
def initialize(short_name, name)
@short_name = short_name
@name = name
@client_action = client_action
end

end

module RunnerActions
def get_new_round_description
RunnerAction.new('new', 'get_new_round_description', TDL::ClientActions.stop)
RunnerAction.new('new', 'get_new_round_description')
end

def deploy_to_production
RunnerAction.new('deploy', 'deploy_to_production', TDL::ClientActions.publish)
RunnerAction.new('deploy', 'deploy_to_production')
end

def all
Expand Down

0 comments on commit 2ec5549

Please sign in to comment.