kirei 0.4.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/kirei/model/class_methods.rb +31 -3
- data/lib/kirei/routing/rack_env_type.rb +2 -2
- data/lib/kirei/services/runner.rb +21 -8
- data/lib/kirei/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea3eb5dc8a6ee187383e7b287491e9454a5c4aebdc77be57bd072b95d293c227
|
4
|
+
data.tar.gz: 63320aa40f86c0be7efbfe3c64f5d4dbb0a56124abc304f7f9b1eac356390504
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c637488aed457873e0f4f929446356fc2cce3a381f3c19dfb13ca0bed53bb3b3a77b0e749637fd47b23aad50690b77973f41b39c8ccbeda9457361a9a407f9d
|
7
|
+
data.tar.gz: 5eed46d30bf6558b76cd8735928db3e8be1563a67d7a0bc36139b0a650dc40f6b39d03a5f85b35ff54bf5aecddc2b4a1926a810e2d6be119217d09f4e1189f58
|
data/README.md
CHANGED
@@ -85,12 +85,40 @@ module Kirei
|
|
85
85
|
return unless App.config.db_extensions.include?(:pg_json)
|
86
86
|
|
87
87
|
attributes.each_pair do |key, value|
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
if vector_column?(key.to_s)
|
89
|
+
attributes[key] = cast_to_vector(value)
|
90
|
+
elsif value.is_a?(Hash) || value.is_a?(Array)
|
91
|
+
attributes[key] = T.unsafe(Sequel).pg_jsonb_wrap(value)
|
92
|
+
end
|
91
93
|
end
|
92
94
|
end
|
93
95
|
|
96
|
+
#
|
97
|
+
# install the gem "pgvector" if you need to use vector columns
|
98
|
+
# also add `:pgvector` to the `App.config.db_extensions` array
|
99
|
+
# and enable the vector extension on the database.
|
100
|
+
#
|
101
|
+
sig { params(column_name: String).returns(T::Boolean) }
|
102
|
+
def vector_column?(column_name)
|
103
|
+
_col_name, col_info = T.let(
|
104
|
+
db.schema(table_name.to_sym).find { _1[0] == column_name.to_sym },
|
105
|
+
[Symbol, T::Hash[Symbol, T.untyped]],
|
106
|
+
)
|
107
|
+
col_info.fetch(:db_type).match?(/vector\(\d+\)/)
|
108
|
+
end
|
109
|
+
|
110
|
+
# New method to cast an array to a vector
|
111
|
+
sig { params(value: T.any(T::Array[Numeric], Sequel::SQL::Expression)).returns(Sequel::SQL::Expression) }
|
112
|
+
def cast_to_vector(value)
|
113
|
+
return value if value.is_a?(Sequel::SQL::Expression) || value.is_a?(Sequel::SQL::PlaceholderLiteralString)
|
114
|
+
|
115
|
+
Kernel.raise("'pg_array' extension is not enabled") unless db.extension(:pg_array)
|
116
|
+
|
117
|
+
pg_array = T.unsafe(Sequel).pg_array(value)
|
118
|
+
|
119
|
+
Sequel.lit("?::vector", pg_array)
|
120
|
+
end
|
121
|
+
|
94
122
|
sig do
|
95
123
|
override.params(
|
96
124
|
hash: T::Hash[Symbol, T.untyped],
|
@@ -10,7 +10,7 @@ module Kirei
|
|
10
10
|
sig do
|
11
11
|
type_parameters(:T)
|
12
12
|
.params(
|
13
|
-
class_name: T.untyped,
|
13
|
+
class_name: T.untyped, # @TODO(lud, 17.08.2024): replace all non-word characters with `.`?
|
14
14
|
log_tags: T::Hash[String, T.untyped],
|
15
15
|
block: T.proc.returns(T.type_parameter(:T)),
|
16
16
|
).returns(T.type_parameter(:T))
|
@@ -24,12 +24,7 @@ module Kirei
|
|
24
24
|
stop = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
25
25
|
latency_in_ms = stop - T.must(start)
|
26
26
|
|
27
|
-
result =
|
28
|
-
when Services::Result
|
29
|
-
service.success? ? "success" : "failure"
|
30
|
-
else
|
31
|
-
"unknown"
|
32
|
-
end
|
27
|
+
result = service_result(service)
|
33
28
|
|
34
29
|
metric_tags = Logging::Metric.inject_defaults({ "service.result" => result })
|
35
30
|
::StatsD.measure(class_name, latency_in_ms, tags: metric_tags)
|
@@ -42,13 +37,31 @@ module Kirei
|
|
42
37
|
}
|
43
38
|
logtags.merge!(log_tags)
|
44
39
|
|
45
|
-
Logging::Logger.call(level:
|
40
|
+
Logging::Logger.call(level: log_level(result), label: "Service Finished", meta: logtags)
|
46
41
|
end
|
47
42
|
|
48
43
|
sig { params(proc: T.proc.returns(T.untyped)).returns(String) }
|
49
44
|
private_class_method def self.source_location(proc)
|
50
45
|
proc.source_location.join(":").gsub(App.root.to_s, "")
|
51
46
|
end
|
47
|
+
|
48
|
+
sig { params(service: T.untyped).returns(String) }
|
49
|
+
def self.service_result(service)
|
50
|
+
case service
|
51
|
+
when Services::Result
|
52
|
+
service.success? ? "success" : "failure"
|
53
|
+
else
|
54
|
+
"unknown"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
sig { params(result: String).returns(Logging::Level) }
|
59
|
+
private_class_method def self.log_level(result)
|
60
|
+
return Logging::Level::INFO if result == "success"
|
61
|
+
return Logging::Level::WARN if result == "failure"
|
62
|
+
|
63
|
+
Logging::Level::UNKNOWN
|
64
|
+
end
|
52
65
|
end
|
53
66
|
end
|
54
67
|
end
|
data/lib/kirei/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kirei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ludwig Reinmiedl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|