mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Remove user_id and points_count parameters from Metrics::Archives::Operation and related calls.
This commit is contained in:
parent
f4aba0991c
commit
670d2e1df7
7 changed files with 26 additions and 36 deletions
|
|
@ -3,11 +3,9 @@
|
||||||
class Metrics::Archives::Operation
|
class Metrics::Archives::Operation
|
||||||
OPERATIONS = %w[archive verify clear restore].freeze
|
OPERATIONS = %w[archive verify clear restore].freeze
|
||||||
|
|
||||||
def initialize(operation:, status:, user_id: nil, points_count: 0)
|
def initialize(operation:, status:)
|
||||||
@operation = operation
|
@operation = operation
|
||||||
@status = status # 'success' or 'failure'
|
@status = status # 'success' or 'failure'
|
||||||
@user_id = user_id
|
|
||||||
@points_count = points_count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,10 @@ module Points
|
||||||
end
|
end
|
||||||
|
|
||||||
def archive_specific_month(user_id, year, month)
|
def archive_specific_month(user_id, year, month)
|
||||||
month_data = {
|
# Direct call without error handling - allows errors to propagate
|
||||||
'user_id' => user_id,
|
# This is intended for use in tests and manual operations where
|
||||||
'year' => year,
|
# we want to know immediately if something went wrong
|
||||||
'month' => month
|
archive_month(user_id, year, month)
|
||||||
}
|
|
||||||
|
|
||||||
process_month(month_data)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
@ -83,8 +80,7 @@ module Points
|
||||||
# Report successful archive operation
|
# Report successful archive operation
|
||||||
Metrics::Archives::Operation.new(
|
Metrics::Archives::Operation.new(
|
||||||
operation: 'archive',
|
operation: 'archive',
|
||||||
status: 'success',
|
status: 'success'
|
||||||
user_id: user_id
|
|
||||||
).call
|
).call
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
@ -99,8 +95,7 @@ module Points
|
||||||
# Report failed archive operation
|
# Report failed archive operation
|
||||||
Metrics::Archives::Operation.new(
|
Metrics::Archives::Operation.new(
|
||||||
operation: 'archive',
|
operation: 'archive',
|
||||||
status: 'failure',
|
status: 'failure'
|
||||||
user_id: user_id
|
|
||||||
).call
|
).call
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -117,7 +112,7 @@ module Points
|
||||||
verification_result = verify_archive_immediately(archive, point_ids)
|
verification_result = verify_archive_immediately(archive, point_ids)
|
||||||
unless verification_result[:success]
|
unless verification_result[:success]
|
||||||
Rails.logger.error("Immediate verification failed: #{verification_result[:error]}")
|
Rails.logger.error("Immediate verification failed: #{verification_result[:error]}")
|
||||||
archive.destroy # Cleanup failed archive
|
archive.destroy # Cleanup failed archive
|
||||||
raise StandardError, "Archive verification failed: #{verification_result[:error]}"
|
raise StandardError, "Archive verification failed: #{verification_result[:error]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -206,7 +201,7 @@ module Points
|
||||||
year: year,
|
year: year,
|
||||||
month: month,
|
month: month,
|
||||||
chunk_number: chunk_number,
|
chunk_number: chunk_number,
|
||||||
point_count: actual_count, # Use actual count, not assumed
|
point_count: actual_count, # Use actual count, not assumed
|
||||||
point_ids_checksum: calculate_checksum(point_ids),
|
point_ids_checksum: calculate_checksum(point_ids),
|
||||||
archived_at: Time.current,
|
archived_at: Time.current,
|
||||||
metadata: {
|
metadata: {
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,7 @@ module Points
|
||||||
# Report successful clear operation
|
# Report successful clear operation
|
||||||
Metrics::Archives::Operation.new(
|
Metrics::Archives::Operation.new(
|
||||||
operation: 'clear',
|
operation: 'clear',
|
||||||
status: 'success',
|
status: 'success'
|
||||||
user_id: archive.user_id,
|
|
||||||
points_count: cleared_count
|
|
||||||
).call
|
).call
|
||||||
|
|
||||||
# Report points removed (cleared from database)
|
# Report points removed (cleared from database)
|
||||||
|
|
@ -95,8 +93,7 @@ module Points
|
||||||
# Report failed clear operation
|
# Report failed clear operation
|
||||||
Metrics::Archives::Operation.new(
|
Metrics::Archives::Operation.new(
|
||||||
operation: 'clear',
|
operation: 'clear',
|
||||||
status: 'failure',
|
status: 'failure'
|
||||||
user_id: archive.user_id
|
|
||||||
).call
|
).call
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,7 @@ module Points
|
||||||
# Report successful restore operation
|
# Report successful restore operation
|
||||||
Metrics::Archives::Operation.new(
|
Metrics::Archives::Operation.new(
|
||||||
operation: 'restore',
|
operation: 'restore',
|
||||||
status: 'success',
|
status: 'success'
|
||||||
user_id: user_id,
|
|
||||||
points_count: total_points
|
|
||||||
).call
|
).call
|
||||||
|
|
||||||
# Report points restored (removed from archived state)
|
# Report points restored (removed from archived state)
|
||||||
|
|
@ -35,8 +33,7 @@ module Points
|
||||||
# Report failed restore operation
|
# Report failed restore operation
|
||||||
Metrics::Archives::Operation.new(
|
Metrics::Archives::Operation.new(
|
||||||
operation: 'restore',
|
operation: 'restore',
|
||||||
status: 'failure',
|
status: 'failure'
|
||||||
user_id: user_id
|
|
||||||
).call
|
).call
|
||||||
|
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,7 @@ module Points
|
||||||
# Report successful verification operation
|
# Report successful verification operation
|
||||||
Metrics::Archives::Operation.new(
|
Metrics::Archives::Operation.new(
|
||||||
operation: 'verify',
|
operation: 'verify',
|
||||||
status: 'success',
|
status: 'success'
|
||||||
user_id: archive.user_id
|
|
||||||
).call
|
).call
|
||||||
|
|
||||||
# Report verification duration
|
# Report verification duration
|
||||||
|
|
@ -69,8 +68,7 @@ module Points
|
||||||
# Report failed verification operation
|
# Report failed verification operation
|
||||||
Metrics::Archives::Operation.new(
|
Metrics::Archives::Operation.new(
|
||||||
operation: 'verify',
|
operation: 'verify',
|
||||||
status: 'failure',
|
status: 'failure'
|
||||||
user_id: archive.user_id
|
|
||||||
).call
|
).call
|
||||||
|
|
||||||
# Report verification duration with check name
|
# Report verification duration with check name
|
||||||
|
|
@ -85,8 +83,7 @@ module Points
|
||||||
# Report failed verification operation
|
# Report failed verification operation
|
||||||
Metrics::Archives::Operation.new(
|
Metrics::Archives::Operation.new(
|
||||||
operation: 'verify',
|
operation: 'verify',
|
||||||
status: 'failure',
|
status: 'failure'
|
||||||
user_id: archive.user_id
|
|
||||||
).call
|
).call
|
||||||
|
|
||||||
# Report verification duration
|
# Report verification duration
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,14 @@ FactoryBot.define do
|
||||||
point_count { 100 }
|
point_count { 100 }
|
||||||
point_ids_checksum { Digest::SHA256.hexdigest('1,2,3') }
|
point_ids_checksum { Digest::SHA256.hexdigest('1,2,3') }
|
||||||
archived_at { Time.current }
|
archived_at { Time.current }
|
||||||
metadata { { format_version: 1, compression: 'gzip' } }
|
metadata do
|
||||||
|
{
|
||||||
|
format_version: 1,
|
||||||
|
compression: 'gzip',
|
||||||
|
expected_count: point_count,
|
||||||
|
actual_count: point_count
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
after(:build) do |archive|
|
after(:build) do |archive|
|
||||||
# Attach a test file
|
# Attach a test file
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,8 @@ require 'prometheus_exporter/client'
|
||||||
|
|
||||||
RSpec.describe Metrics::Archives::Operation do
|
RSpec.describe Metrics::Archives::Operation do
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
subject(:operation) { described_class.new(operation: operation_type, status: status, user_id: user_id).call }
|
subject(:operation) { described_class.new(operation: operation_type, status: status).call }
|
||||||
|
|
||||||
let(:user_id) { 123 }
|
|
||||||
let(:operation_type) { 'archive' }
|
let(:operation_type) { 'archive' }
|
||||||
let(:status) { 'success' }
|
let(:status) { 'success' }
|
||||||
let(:prometheus_client) { instance_double(PrometheusExporter::Client) }
|
let(:prometheus_client) { instance_double(PrometheusExporter::Client) }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue