Skip to content

Commit f0b5829

Browse files
authored
Merge pull request #879 from code0-tech/867-implement-flow-validation
Add flow validation with triangulum
2 parents fbc8a5e + a827020 commit f0b5829

32 files changed

Lines changed: 389 additions & 15 deletions

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ gem 'good_job', '~> 4.0'
7979
gem 'rotp'
8080

8181
gem 'grpc', '~> 1.67'
82-
gem 'tucana', '0.0.58'
82+
gem 'tucana', '0.0.62'
8383

8484
gem 'code0-identities', '~> 0.0.3'
8585

@@ -91,3 +91,5 @@ gem 'code0-zero_track', '0.0.6'
9191
gem 'image_processing', '>= 1.2'
9292

9393
gem 'json-schema', '~> 6.0'
94+
95+
gem 'triangulum', '0.5.2'

Gemfile.lock

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ GEM
161161
pp (>= 0.6.0)
162162
rdoc (>= 4.0.0)
163163
reline (>= 0.4.2)
164-
json (2.12.2)
164+
json (2.19.2)
165165
json-schema (6.1.0)
166166
addressable (~> 2.8)
167167
bigdecimal (>= 3.1, < 5)
@@ -203,6 +203,7 @@ GEM
203203
nokogiri (1.18.10)
204204
mini_portile2 (~> 2.8.2)
205205
racc (~> 1.4)
206+
open3 (0.2.1)
206207
parallel (1.27.0)
207208
parser (3.3.10.0)
208209
ast (~> 2.4.1)
@@ -376,8 +377,13 @@ GEM
376377
test-prof (1.5.0)
377378
thor (1.4.0)
378379
timeout (0.6.0)
380+
triangulum (0.5.2)
381+
base64 (~> 0.3)
382+
json (~> 2.19)
383+
open3 (~> 0.2)
384+
tucana (~> 0.0, >= 0.0.62)
379385
tsort (0.2.0)
380-
tucana (0.0.58)
386+
tucana (0.0.62)
381387
grpc (~> 1.64)
382388
tzinfo (2.0.6)
383389
concurrent-ruby (~> 1.0)
@@ -431,7 +437,8 @@ DEPENDENCIES
431437
simplecov (~> 0.22.0)
432438
simplecov-cobertura (~> 3.0)
433439
test-prof (~> 1.0)
434-
tucana (= 0.0.58)
440+
triangulum (= 0.5.2)
441+
tucana (= 0.0.62)
435442
tzinfo-data
436443

437444
RUBY VERSION

app/finders/data_types_finder.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ def by_data_type(data_types)
2929
def by_runtime_function_definition(data_types)
3030
return data_types unless params[:runtime_function_definition]
3131

32-
data_types.where(id: params[:runtime_function_definition].referenced_data_types.pluck(:id))
32+
referenced_data_types_ids = RuntimeFunctionDefinitionDataTypeLink
33+
.where(runtime_function_definition: params[:runtime_function_definition])
34+
.select(:referenced_data_type_id)
35+
36+
data_types.where(id: referenced_data_types_ids)
3337
end
3438

3539
def by_flow_type_setting(data_types)

app/graphql/types/flow_type.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class FlowType < Types::BaseObject
88

99
field :name, String, null: false, description: 'Name of the flow'
1010

11+
field :validation_status, Types::FlowValidationStatusEnum,
12+
null: false,
13+
description: 'The validation status of the flow'
14+
1115
field :input_type, String,
1216
null: true,
1317
description: 'The input data type of the flow'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class FlowValidationStatusEnum < Types::BaseEnum
5+
description 'The validation status of a flow.'
6+
7+
value :UNVALIDATED, 'The flow has not been validated yet.', value: 'unvalidated'
8+
value :VALID, 'The flow has been validated and is valid.', value: 'valid'
9+
value :INVALID, 'The flow has been validated and is invalid.', value: 'invalid'
10+
end
11+
end

app/grpc/flow_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class FlowHandler < Tucana::Sagittarius::FlowService::Service
1010
def self.update_runtime(runtime)
1111
flows = []
1212
runtime.project_assignments.compatible.each do |assignment|
13-
assignment.namespace_project.flows.each do |flow|
13+
assignment.namespace_project.flows.validation_status_valid.each do |flow|
1414
flows << flow.to_grpc
1515
end
1616
end

app/jobs/flow_validation_job.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
class FlowValidationJob < ApplicationJob
4+
def perform(flow_id)
5+
flow = Flow.find_by(id: flow_id)
6+
return if flow.nil?
7+
8+
Namespaces::Projects::Flows::ValidationService.new(flow).execute
9+
end
10+
end

app/models/data_type.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,18 @@ def validate_version
3030
def parsed_version
3131
Gem::Version.new(version)
3232
end
33+
34+
def to_grpc
35+
Tucana::Shared::DefinitionDataType.new(
36+
identifier: identifier,
37+
name: names.map(&:to_grpc),
38+
display_message: display_messages.map(&:to_grpc),
39+
alias: aliases.map(&:to_grpc),
40+
rules: rules.map(&:to_grpc),
41+
generic_keys: generic_keys,
42+
type: type,
43+
linked_data_type_identifiers: referenced_data_types.map(&:identifier),
44+
version: version
45+
)
46+
end
3347
end

app/models/data_type_rule.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ class DataTypeRule < ApplicationRecord
2626
filename: 'data_types/RegexRuleConfig',
2727
hash_conversion: true,
2828
}
29+
30+
def to_grpc
31+
Tucana::Shared::DefinitionDataTypeRule.create(variant.to_sym, config)
32+
end
2933
end

app/models/flow.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
# frozen_string_literal: true
22

33
class Flow < ApplicationRecord
4+
VALIDATION_STATUS = {
5+
unvalidated: 0,
6+
valid: 1,
7+
invalid: 2,
8+
}.with_indifferent_access
9+
410
belongs_to :project, class_name: 'NamespaceProject'
511
belongs_to :flow_type
612
belongs_to :starting_node, class_name: 'NodeFunction', optional: true
713

14+
enum :validation_status, VALIDATION_STATUS, prefix: :validation_status
15+
816
has_many :flow_settings, class_name: 'FlowSetting', inverse_of: :flow
917
has_many :node_functions, class_name: 'NodeFunction', inverse_of: :flow
1018

1119
has_many :flow_data_type_links, inverse_of: :flow
1220
has_many :referenced_data_types, through: :flow_data_type_links, source: :referenced_data_type
1321

22+
validates :validation_status,
23+
presence: true,
24+
inclusion: {
25+
in: VALIDATION_STATUS.keys.map(&:to_s),
26+
}
27+
1428
validates :name, presence: true,
1529
allow_blank: false,
1630
uniqueness: { case_sensitive: false, scope: :project_id }

0 commit comments

Comments
 (0)