lex-metering 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e70bf639989419388bb625a4f105d7ad6376b534b35f839d8623427bfc3fe43
4
- data.tar.gz: b6c1250c1e19d2d80ee88772416aa4b3f05f4123b774698b6b4ae6ef5b6f02a4
3
+ metadata.gz: f6ed98a119f0cd8391dfcbabef08384a0ead7ff8f9cfd45added086ce825ddef
4
+ data.tar.gz: 47b5dc7406297ff5c9bec985b4d4ef2d0d554cc3cea0c0c489305d545c22b07f
5
5
  SHA512:
6
- metadata.gz: d65a2b2829f638b80ce726b19c616f81a4dc4c436482bea8bee837d489053070b929f59fe240e09dff4478be52cdce3dee43aa127cc21dea0b49833b920ec246
7
- data.tar.gz: 614785e8c7af6964c0312c5f18ff362c0fd1f7e29656e6db76cd94c2029774108050671363adb8b17012f334ce71e86750f6547eae298490875fde11637c092c
6
+ metadata.gz: be6917d55265e01b080e4165de8c5df74c41ab38738ad6400e0fe84188d61e5e022ec806f0fb19e705fa2d04a5877d33892f744978c18a018e8dda9ef25784ec
7
+ data.tar.gz: d12d6e44b297b5d533a3f6e49764f9fbd3a4e74a86594c83c1a5e13812a6654f08667f81fc5a84a34368a75cf8b8c8a11933bc894ba4f5aa1833070608749d40
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.3] - 2026-03-18
4
+
5
+ ### Fixed
6
+ - `worker_costs` period filtering now uses cross-DB `Sequel.lit('recorded_at >= ?', cutoff)` with Ruby time arithmetic instead of PostgreSQL-only `CURRENT_TIMESTAMP - INTERVAL` syntax
7
+
3
8
  ## [0.1.2] - 2026-03-17
4
9
 
5
10
  ### Changed
data/CLAUDE.md CHANGED
@@ -11,7 +11,7 @@ Captures LLM token usage metrics per task for cost attribution and intelligent r
11
11
  ## Gem Info
12
12
 
13
13
  - **Gem name**: `lex-metering`
14
- - **Version**: `0.1.0`
14
+ - **Version**: `0.1.3`
15
15
  - **Module**: `Legion::Extensions::Metering`
16
16
  - **Ruby**: `>= 3.4`
17
17
  - **License**: MIT
@@ -72,4 +72,4 @@ lib/legion/extensions/metering/
72
72
  - Extension has `data_required? true` (both at module level and instance level) — will skip loading if `legion-data` is not connected
73
73
  - No explicit actors — gets auto-generated subscription actors from the framework
74
74
  - `routing_stats` uses `select_append { avg(latency_ms).as(avg_latency) }` — Sequel virtual row syntax
75
- - Time interval filtering uses `Sequel.lit("CURRENT_TIMESTAMP - INTERVAL '...'")` which is PostgreSQL syntax; SQLite uses different interval syntax (known limitation)
75
+ - Time interval filtering uses `Sequel.lit('recorded_at >= ?', cutoff)` with Ruby `Time` arithmetic for cross-database compatibility (PostgreSQL, SQLite, MySQL)
@@ -5,6 +5,8 @@ module Legion
5
5
  module Metering
6
6
  module Runners
7
7
  module Metering
8
+ PERIOD_DAYS = { 'daily' => 1, 'weekly' => 7, 'monthly' => 30 }.freeze
9
+
8
10
  def record(worker_id: nil, task_id: nil, provider: nil, model_id: nil,
9
11
  input_tokens: 0, output_tokens: 0, thinking_tokens: 0,
10
12
  input_context_bytes: 0, latency_ms: 0, routing_reason: nil,
@@ -35,15 +37,7 @@ module Legion
35
37
 
36
38
  def worker_costs(worker_id:, period: 'daily', **)
37
39
  ds = Legion::Data.connection[:metering_records].where(worker_id: worker_id)
38
-
39
- case period
40
- when 'daily'
41
- ds = ds.where { recorded_at >= Sequel.lit("CURRENT_TIMESTAMP - INTERVAL '1 day'") }
42
- when 'weekly'
43
- ds = ds.where { recorded_at >= Sequel.lit("CURRENT_TIMESTAMP - INTERVAL '7 days'") }
44
- when 'monthly'
45
- ds = ds.where { recorded_at >= Sequel.lit("CURRENT_TIMESTAMP - INTERVAL '30 days'") }
46
- end
40
+ ds = apply_period_filter(ds, period)
47
41
 
48
42
  {
49
43
  worker_id: worker_id,
@@ -93,6 +87,16 @@ module Legion
93
87
  Legion::Logging.info "[metering] cleanup: purged=#{count} retention_days=#{retention_days} cutoff=#{cutoff}"
94
88
  { purged: count, retention_days: retention_days, cutoff: cutoff }
95
89
  end
90
+
91
+ private
92
+
93
+ def apply_period_filter(dataset, period)
94
+ days = PERIOD_DAYS[period]
95
+ return dataset unless days
96
+
97
+ cutoff = Time.now.utc - (days * 86_400)
98
+ dataset.where(::Sequel.lit('recorded_at >= ?', cutoff))
99
+ end
96
100
  end
97
101
  end
98
102
  end
@@ -3,7 +3,7 @@
3
3
  module Legion
4
4
  module Extensions
5
5
  module Metering
6
- VERSION = '0.1.2'
6
+ VERSION = '0.1.3'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-metering
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity