mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
34 lines
850 B
Ruby
34 lines
850 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Stats::CalculatingJob < ApplicationJob
|
|
queue_as :stats
|
|
|
|
def perform(user_id, start_at: nil, end_at: nil)
|
|
Stats::Calculate.new(user_id, start_at:, end_at:).call
|
|
|
|
create_stats_updated_notification(user_id)
|
|
rescue StandardError => e
|
|
create_stats_update_failed_notification(user_id, e)
|
|
end
|
|
|
|
private
|
|
|
|
def create_stats_updated_notification(user_id)
|
|
user = User.find(user_id)
|
|
|
|
Notifications::Create.new(
|
|
user:, kind: :info, title: 'Stats updated', content: 'Stats updated'
|
|
).call
|
|
end
|
|
|
|
def create_stats_update_failed_notification(user_id, error)
|
|
user = User.find(user_id)
|
|
|
|
Notifications::Create.new(
|
|
user:,
|
|
kind: :error,
|
|
title: 'Stats update failed',
|
|
content: "#{error.message}, stacktrace: #{error.backtrace.join("\n")}"
|
|
).call
|
|
end
|
|
end
|