Skip to content

Commit 03ef09e

Browse files
committed
Fix handling of invalid definitions
1 parent 315fff7 commit 03ef09e

6 files changed

Lines changed: 86 additions & 81 deletions

File tree

app/services/runtimes/grpc/data_types/update_service.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,8 @@ def execute
3131
data_type_links_to_update = []
3232

3333
sorted_data_types_response.payload.each do |data_type|
34-
db_data_type = update_datatype(data_type)
35-
if db_data_type.persisted?
36-
data_type_links_to_update << [db_data_type, data_type.linked_data_type_identifiers]
37-
next
38-
end
39-
40-
logger.error(message: 'Failed to update data type',
41-
runtime_id: current_runtime.id,
42-
data_type_identifier: data_type.identifier,
43-
errors: db_data_type.errors.full_messages)
44-
45-
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update data type',
46-
error_code: :invalid_data_type, details: db_data_type.errors)
34+
db_data_type = update_datatype(data_type, t)
35+
data_type_links_to_update << [db_data_type, data_type.linked_data_type_identifiers]
4736
end
4837

4938
data_type_links_to_update.each do |db_data_type, linked_data_type_identifiers|
@@ -137,7 +126,7 @@ def enqueue_runtime_compatibility_update
137126
UpdateRuntimeCompatibilityJob.perform_later({ runtime_id: current_runtime.id })
138127
end
139128

140-
def update_datatype(data_type)
129+
def update_datatype(data_type, t)
141130
db_object = DataType.find_or_initialize_by(runtime: current_runtime, identifier: data_type.identifier)
142131
db_object.removed_at = nil
143132
db_object.type = data_type.type
@@ -149,7 +138,20 @@ def update_datatype(data_type)
149138
db_object.version = data_type.version
150139
db_object.definition_source = data_type.definition_source
151140
db_object.runtime_module = runtime_module_resolver.call(data_type)
152-
db_object.save
141+
142+
unless db_object.save
143+
logger.error(message: 'Failed to update data type',
144+
module_identifier: db_object.runtime_module&.identifier,
145+
data_type_identifier: data_type.identifier,
146+
errors: db_object.errors.full_messages)
147+
148+
t.rollback_and_return! ServiceResponse.error(
149+
message: 'Failed to update data type',
150+
error_code: :invalid_data_type,
151+
details: db_object.errors
152+
)
153+
end
154+
153155
db_object
154156
end
155157

app/services/runtimes/grpc/flow_types/update_service.rb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,7 @@ def execute
2525
.update_all(removed_at: Time.zone.now)
2626
# rubocop:enable Rails/SkipsModelValidations
2727
flow_types.each do |flow_type|
28-
db_flow_type = update_flowtype(flow_type, t)
29-
next if db_flow_type.persisted?
30-
31-
logger.error(
32-
message: 'Failed to update flow type',
33-
runtime_id: current_runtime.id,
34-
flow_type_identifier: flow_type.identifier,
35-
errors: db_flow_type.errors.full_messages
36-
)
37-
38-
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update flow type',
39-
error_code: :invalid_flow_type,
40-
details: db_flow_type.errors)
28+
update_flowtype(flow_type, t)
4129
end
4230

4331
enqueue_runtime_compatibility_update
@@ -73,7 +61,20 @@ def update_flowtype(flow_type, t)
7361
db_object.runtime_flow_type = find_runtime_flow_type(flow_type, t)
7462
update_settings(flow_type.settings, db_object.flow_type_settings, t)
7563
link_data_types(db_object, flow_type.linked_data_type_identifiers, t)
76-
db_object.save
64+
65+
unless db_object.save
66+
logger.error(
67+
message: 'Failed to update flow type',
68+
module_identifier: runtime_module.identifier,
69+
flow_type_identifier: flow_type.identifier,
70+
errors: db_object.errors.full_messages
71+
)
72+
73+
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update flow type',
74+
error_code: :invalid_flow_type,
75+
details: db_object.errors)
76+
end
77+
7778
db_object
7879
end
7980

app/services/runtimes/grpc/function_definitions/update_service.rb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,7 @@ def execute
2222
mark_existing_function_definitions_as_removed
2323

2424
function_definitions.each do |function_definition|
25-
db_function_definition = update_function_definition(function_definition, t)
26-
next if db_function_definition.persisted?
27-
28-
logger.error(message: 'Failed to update function definition',
29-
runtime_id: current_runtime.id,
30-
module_identifier: runtime_module.identifier,
31-
definition_identifier: function_definition.runtime_name,
32-
errors: db_function_definition.errors.full_messages)
33-
34-
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update function definition',
35-
error_code: :invalid_function_definition,
36-
details: db_function_definition.errors)
25+
update_function_definition(function_definition, t)
3726
end
3827

3928
enqueue_runtime_compatibility_update
@@ -80,9 +69,19 @@ def update_function_definition(function_definition, t)
8069
db_object.display_messages = update_translations(function_definition.display_message,
8170
db_object.display_messages)
8271
db_object.aliases = update_translations(function_definition.alias, db_object.aliases)
83-
db_object.save
8472

85-
update_parameter_definitions(db_object, function_definition.parameter_definitions, t) if db_object.persisted?
73+
unless db_object.save
74+
logger.error(message: 'Failed to update function definition',
75+
module_identifier: runtime_module.identifier,
76+
definition_identifier: function_definition.runtime_name,
77+
errors: db_object.errors.full_messages)
78+
79+
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update function definition',
80+
error_code: :invalid_function_definition,
81+
details: db_object.errors)
82+
end
83+
84+
update_parameter_definitions(db_object, function_definition.parameter_definitions, t)
8685

8786
db_object
8887
end

app/services/runtimes/grpc/module_configuration_definitions/update_service.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,7 @@ def initialize(current_runtime, configuration_definitions, runtime_module:, upda
2121
def execute
2222
transactional do |t|
2323
configuration_definitions.each do |configuration_definition|
24-
db_configuration = update_configuration(configuration_definition, t)
25-
next if db_configuration.persisted?
26-
27-
logger.error(message: 'Failed to update module configuration definition',
28-
runtime_id: current_runtime.id,
29-
module_identifier: runtime_module.identifier,
30-
configuration_identifier: configuration_definition.identifier,
31-
errors: db_configuration.errors.full_messages)
32-
33-
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update module configuration definition',
34-
error_code: :invalid_module_configuration_definition,
35-
details: db_configuration.errors)
24+
update_configuration(configuration_definition, t)
3625
end
3726

3827
enqueue_runtime_compatibility_update
@@ -64,7 +53,18 @@ def update_configuration(configuration, t)
6453
db_object.hidden = configuration.hidden
6554
db_object.names = update_translations(configuration.name, db_object.names)
6655
db_object.descriptions = update_translations(configuration.description, db_object.descriptions)
67-
db_object.save
56+
57+
unless db_object.save
58+
logger.error(message: 'Failed to update module configuration definition',
59+
module_identifier: runtime_module.identifier,
60+
configuration_identifier: configuration.identifier,
61+
errors: db_object.errors.full_messages)
62+
63+
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update module configuration definition',
64+
error_code: :invalid_module_configuration_definition,
65+
details: db_object.errors)
66+
end
67+
6868
link_data_types(db_object, configuration.linked_data_type_identifiers, t) if db_object.persisted?
6969
db_object
7070
end

app/services/runtimes/grpc/runtime_flow_types/update_service.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,7 @@ def execute
2626
# rubocop:enable Rails/SkipsModelValidations
2727

2828
runtime_flow_types.each do |runtime_flow_type|
29-
db_runtime_flow_type = update_runtime_flowtype(runtime_flow_type, t)
30-
next if db_runtime_flow_type.persisted?
31-
32-
logger.error(message: 'Failed to update runtime flow type',
33-
runtime_id: current_runtime.id,
34-
module_identifier: runtime_module.identifier,
35-
runtime_flow_type_identifier: runtime_flow_type.identifier,
36-
errors: db_runtime_flow_type.errors.full_messages)
37-
38-
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update runtime flow type',
39-
error_code: :invalid_flow_type,
40-
details: db_runtime_flow_type.errors)
29+
update_runtime_flowtype(runtime_flow_type, t)
4130
end
4231

4332
enqueue_runtime_compatibility_update
@@ -76,7 +65,20 @@ def update_runtime_flowtype(runtime_flow_type, t)
7665
db_object.version = runtime_flow_type.version
7766
db_object.definition_source = runtime_flow_type.definition_source
7867
db_object.display_icon = runtime_flow_type.display_icon
79-
db_object.save
68+
69+
unless db_object.save
70+
logger.error(message: 'Failed to update runtime flow type',
71+
module_identifier: runtime_module.identifier,
72+
runtime_flow_type_identifier: runtime_flow_type.identifier,
73+
errors: db_object.errors.full_messages)
74+
75+
t.rollback_and_return! ServiceResponse.error(
76+
message: 'Could not save runtime flow type',
77+
error_code: :invalid_flow_type,
78+
details: db_object.errors
79+
)
80+
end
81+
8082
if db_object.persisted?
8183
update_settings(runtime_flow_type.runtime_settings, db_object.runtime_flow_type_settings, t)
8284
link_data_types(db_object, runtime_flow_type.linked_data_type_identifiers, t)

app/services/runtimes/grpc/runtime_function_definitions/update_service.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,7 @@ def execute
2626
runtime_module: runtime_module).update_all(removed_at: Time.zone.now)
2727
# rubocop:enable Rails/SkipsModelValidations
2828
runtime_function_definitions.each do |runtime_function_definition|
29-
response = update_runtime_function_definition(runtime_function_definition, t)
30-
next if response.persisted?
31-
32-
logger.error(message: 'Failed to update runtime function definition',
33-
runtime_id: current_runtime.id,
34-
definition_identifier: runtime_function_definition.runtime_name,
35-
errors: response.errors.full_messages)
36-
37-
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update runtime function definition',
38-
error_code: :invalid_runtime_function_definition,
39-
details: response.errors)
29+
update_runtime_function_definition(runtime_function_definition, t)
4030
end
4131

4232
enqueue_runtime_compatibility_update
@@ -79,7 +69,18 @@ def update_runtime_function_definition(runtime_function_definition, t)
7969
db_object.display_messages)
8070
db_object.aliases = update_translations(runtime_function_definition.alias, db_object.aliases)
8171

82-
db_object.save
72+
unless db_object.save
73+
logger.error(message: 'Failed to update runtime function definition',
74+
module_identifier: runtime_module.identifier,
75+
definition_identifier: runtime_function_definition.runtime_name,
76+
errors: db_object.errors.full_messages)
77+
78+
t.rollback_and_return! ServiceResponse.error(
79+
message: 'Could not save runtime function definition',
80+
error_code: :invalid_runtime_function_definition,
81+
details: db_object.errors
82+
)
83+
end
8384

8485
db_object.parameters = update_parameters(db_object, runtime_function_definition.runtime_parameter_definitions,
8586
db_object.parameters, t)

0 commit comments

Comments
 (0)