Skip to content

Commit 15e8cd4

Browse files
author
Vidas P
committed
Use common logic for working?
1 parent a0c5077 commit 15e8cd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+64
-489
lines changed

.rubocop

Lines changed: 0 additions & 1 deletion
This file was deleted.

.rubocop.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ Lint/AmbiguousBlockAssociation:
3434
Enabled: false
3535
Style/MethodCallWithoutArgsParentheses:
3636
Enabled: false
37-
Rails/TimeZone:
38-
Enabled: false
39-
Rails/Date:
40-
Enabled: false
41-
Rails/OutputSafety:
42-
Enabled: false
4337
Layout/TrailingWhitespace:
4438
Enabled: false
4539
Style/ClassAndModuleChildren:
@@ -50,13 +44,8 @@ Style/FormatStringToken:
5044
Enabled: false
5145
Style/RescueModifier:
5246
Enabled: false
53-
Rails/Blank:
54-
Enabled: false
5547
Metrics/BlockNesting:
5648
Enabled: false
57-
Rails/Present:
58-
Enabled: false
59-
6049

6150
# Temporary disable method size metrics
6251
Metrics/AbcSize:

app/models/agent.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,21 @@ def receive_web_request(_params, _method, _format)
112112
# def receive_web_request(request=ActionDispatch::Request.new( ... ))
113113
# end
114114

115-
# Implement me in your subclass to decide if your Agent is working.
116115
def working?
117-
raise 'Implement me in your subclass'
116+
return false if recent_error_logs?
117+
118+
return false unless received_message_without_error? || checked_without_error? || last_error_log_at.nil?
119+
120+
# Timeouts
121+
if interpolated['expected_update_period_in_days'].present?
122+
return false unless message_created_within?(interpolated['expected_update_period_in_days'])
123+
end
124+
125+
if interpolated['expected_receive_period_in_days'].present?
126+
return false unless last_receive_at && last_receive_at > interpolated['expected_receive_period_in_days'].to_i.days.ago
127+
end
128+
129+
true
118130
end
119131

120132
def build_message(message)

app/models/agents/aftership_agent.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ def default_options
9090
'path' => 'trackings' }
9191
end
9292

93-
def working?
94-
!recent_error_logs?
95-
end
96-
9793
def validate_options
9894
errors.add(:base, 'You need to specify a api key') unless options['api_key'].present?
9995
errors.add(:base, 'You need to specify a path request') unless options['path'].present?

app/models/agents/attribute_difference_agent.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ def validate_options
4949
end
5050
end
5151

52-
def working?
53-
message_created_within?(interpolated['expected_update_period_in_days']) && !recent_error_logs?
54-
end
55-
5652
def receive(incoming_messages)
5753
incoming_messages.each do |message|
5854
handle(interpolated(message), message)

app/models/agents/basecamp_agent.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ def validate_options
5757
errors.add(:base, 'you need to specify the basecamp project id of which you want to receive messages') unless options['project_id'].present?
5858
end
5959

60-
def working?
61-
(messages_count.present? && messages_count > 0)
62-
end
63-
6460
def check
6561
service.prepare_request
6662
response = HTTParty.get messages_url, request_options.merge(query_parameters)

app/models/agents/buffer_agent.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ def validate_options
5555
end
5656
# rubocop:enable Metrics/CyclomaticComplexity
5757

58-
def working?
59-
last_receive_at && last_receive_at > options['expected_receive_period_in_days'].to_i.days.ago && !recent_error_logs?
60-
end
61-
6258
def receive(incoming_messages)
6359
incoming_messages.each do |message|
6460
memory['message_ids'] ||= []

app/models/agents/change_detector_agent.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ def validate_options
3737
end
3838
end
3939

40-
def working?
41-
message_created_within?(interpolated['expected_update_period_in_days']) && !recent_error_logs?
42-
end
43-
4440
def receive(incoming_messages)
4541
incoming_messages.each do |message|
4642
interpolation_context.stack do

app/models/agents/commander_agent.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ class CommanderAgent < Agent
2828
Select Agents that you want to control from this CommanderAgent.
2929
MD
3030

31-
def working?
32-
true
33-
end
34-
3531
def check
3632
control!
3733
end

app/models/agents/csv_agent.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ def validate_options
8686
end
8787
end
8888

89-
def working?
90-
received_message_without_error?
91-
end
92-
9389
def receive(incoming_messages)
9490
case options['mode']
9591
when 'parse'

0 commit comments

Comments
 (0)