Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Reapply "misc: Add scheduler monitoring for sentry if enabled" (#2112) (#2129)" #2148

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ gem 'newrelic_rpm'
gem 'opentelemetry-exporter-otlp'
gem 'opentelemetry-instrumentation-all'
gem 'opentelemetry-sdk'
gem 'sentry-rails', '~> 5.17.0'
gem 'sentry-ruby', '~> 5.17.0'
gem 'sentry-sidekiq', '~> 5.17.0'
gem 'sentry-rails', '~> 5.12.0'
gem 'sentry-ruby', '~> 5.12.0'
gem 'sentry-sidekiq', '~> 5.12.0'

# Storage
gem 'aws-sdk-s3', require: false
Expand Down
17 changes: 8 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -743,14 +743,13 @@ GEM
scenic (1.7.0)
activerecord (>= 4.0.0)
railties (>= 4.0.0)
sentry-rails (5.17.3)
sentry-rails (5.12.0)
railties (>= 5.0)
sentry-ruby (~> 5.17.3)
sentry-ruby (5.17.3)
bigdecimal
sentry-ruby (~> 5.12.0)
sentry-ruby (5.12.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
sentry-sidekiq (5.17.3)
sentry-ruby (~> 5.17.3)
sentry-sidekiq (5.12.0)
sentry-ruby (~> 5.12.0)
sidekiq (>= 3.0)
shellany (0.0.1)
shoulda-matchers (6.2.0)
Expand Down Expand Up @@ -911,9 +910,9 @@ DEPENDENCIES
ruby-lsp-rails
sass-rails
scenic
sentry-rails (~> 5.17.0)
sentry-ruby (~> 5.17.0)
sentry-sidekiq (~> 5.17.0)
sentry-rails (~> 5.12.0)
sentry-ruby (~> 5.12.0)
sentry-sidekiq (~> 5.12.0)
shoulda-matchers
sidekiq
simplecov
Expand Down
5 changes: 2 additions & 3 deletions app/jobs/clock/activate_subscriptions_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

module Clock
class ActivateSubscriptionsJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

unique :until_executed, on_conflict: :log

def perform(*)
def perform
Subscriptions::ActivateService.new(timestamp: Time.current.to_i).activate_all_pending
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/create_interval_wallet_transactions_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class CreateIntervalWalletTransactionsJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
Wallets::CreateIntervalWalletTransactionsService.call
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/events_validation_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

module Clock
class EventsValidationJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

unique :until_executed

def perform(*)
def perform
# NOTE: refresh the last hour events materialized view
Scenic.database.refresh_materialized_view(
Events::LastHourMv.table_name,
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/finalize_invoices_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class FinalizeInvoicesJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
Invoice.ready_to_be_finalized.each do |invoice|
Invoices::FinalizeJob.perform_later(invoice)
end
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/free_trial_subscriptions_biller_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class FreeTrialSubscriptionsBillerJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
Subscriptions::FreeTrialBillingService.call
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/refresh_draft_invoices_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class RefreshDraftInvoicesJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
Invoice.ready_to_be_refreshed.find_each do |invoice|
Invoices::RefreshDraftJob.perform_later(invoice)
end
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/refresh_wallets_ongoing_balance_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class RefreshWalletsOngoingBalanceJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
return unless License.premium?

Wallet.active.find_each do |wallet|
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/subscriptions_biller_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class SubscriptionsBillerJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
Subscriptions::BillingService.call
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/subscriptions_to_be_terminated_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class SubscriptionsToBeTerminatedJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
Subscription
.joins(customer: :organization)
.joins('left join webhooks on subscriptions.id = webhooks.object_id and ' \
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/terminate_coupons_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class TerminateCouponsJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
Coupons::TerminateService.new.terminate_all_expired
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/terminate_ended_subscriptions_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class TerminateEndedSubscriptionsJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
Subscription
.joins(customer: :organization)
.active
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/terminate_wallets_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class TerminateWalletsJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
Wallet.active.expired.find_each do |wallet|
Wallets::TerminateService.call(wallet:)
end
Expand Down
4 changes: 1 addition & 3 deletions app/jobs/clock/webhooks_cleanup_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module Clock
class WebhooksCleanupJob < ApplicationJob
prepend SentryCronConcern

queue_as 'clock'

def perform(*)
def perform
Webhook.where('updated_at < ?', 90.days.ago).destroy_all
end
end
Expand Down
17 changes: 0 additions & 17 deletions app/jobs/concerns/sentry_cron_concern.rb

This file was deleted.

54 changes: 13 additions & 41 deletions clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,85 +19,57 @@ module Clockwork
# NOTE: All clocks run every hour to take customer timezones into account

every(5.minutes, 'schedule:activate_subscriptions') do
Clock::ActivateSubscriptionsJob.perform_later(
slug: 'activate_subscriptions', cron: '*/5 * * * *'
)
Clock::ActivateSubscriptionsJob.perform_later
end

every(5.minutes, 'schedule:refresh_draft_invoices') do
Clock::RefreshDraftInvoicesJob.perform_later(
slug: 'lago_refresh_draft_invoices', cron: '*/5 * * * *'
)
Clock::RefreshDraftInvoicesJob.perform_later
end

if ENV['LAGO_MEMCACHE_SERVERS'].present? || ENV['LAGO_REDIS_CACHE_URL'].present?
every(5.minutes, 'schedule:refresh_wallets_ongoing_balance') do
unless ActiveModel::Type::Boolean.new.cast(ENV['LAGO_DISABLE_WALLET_REFRESH'])
Clock::RefreshWalletsOngoingBalanceJob.perform_later(
slug: 'lago_refresh_wallets_ongoing_balance', cron: '*/5 * * * *'
)
end
Clock::RefreshWalletsOngoingBalanceJob.perform_later unless ENV['LAGO_DISABLE_WALLET_REFRESH'] == 'true'
end
end

every(1.hour, 'schedule:terminate_ended_subscriptions', at: '*:05') do
Clock::TerminateEndedSubscriptionsJob.perform_later(
slug: 'lago_terminate_ended_subscriptions', cron: '5 */1 * * *'
)
Clock::TerminateEndedSubscriptionsJob.perform_later
end

every(1.hour, 'schedule:bill_customers', at: '*:10') do
Clock::SubscriptionsBillerJob.perform_later(
slug: 'lago_bill_customers', cron: '10 */1 * * *'
)
Clock::SubscriptionsBillerJob.perform_later
end

every(1.hour, 'schedule:finalize_invoices', at: '*:20') do
Clock::FinalizeInvoicesJob.perform_later(
slug: 'lago_finalize_invoices', cron: '20 */1 * * *'
)
Clock::FinalizeInvoicesJob.perform_later
end

every(1.hour, 'schedule:terminate_coupons', at: '*:30') do
Clock::TerminateCouponsJob.perform_later(
slug: 'lago_terminate_coupons', cron: '30 */1 * * *'
)
Clock::TerminateCouponsJob.perform_later
end

every(1.hour, 'schedule:bill_ended_trial_subscriptions', at: '*:35') do
Clock::FreeTrialSubscriptionsBillerJob.perform_later(
slug: 'lago_bill_ended_trial_subscriptions', cron: '35 */1 * * *'
)
Clock::FreeTrialSubscriptionsBillerJob.perform_later
end

every(1.hour, 'schedule:terminate_wallets', at: '*:45') do
Clock::TerminateWalletsJob.perform_later(
slug: 'lago_terminate_wallets', cron: '45 */1 * * *'
)
Clock::TerminateWalletsJob.perform_later
end

every(1.hour, 'schedule:termination_alert', at: '*:50') do
Clock::SubscriptionsToBeTerminatedJob.perform_later(
slug: 'lago_termination_alert', cron: '50 */1 * * *'
)
Clock::SubscriptionsToBeTerminatedJob.perform_later
end

every(1.hour, 'schedule:top_up_wallet_interval_credits', at: '*:55') do
Clock::CreateIntervalWalletTransactionsJob.perform_later(
slug: 'lago_top_up_wallet_interval_credits', cron: '55 */1 * * *'
)
Clock::CreateIntervalWalletTransactionsJob.perform_later
end

every(1.day, 'schedule:clean_webhooks', at: '01:00') do
Clock::WebhooksCleanupJob.perform_later(
slug: 'lago_clean_webhooks', cron: '0 1 * * *'
)
Clock::WebhooksCleanupJob.perform_later
end

every(1.hour, 'schedule:post_validate_events', at: '*:05') do
Clock::EventsValidationJob.perform_later(
slug: 'lago_post_validate_events', cron: '5 */1 * * *'
)
Clock::EventsValidationJob.perform_later
rescue => e
Sentry.capture_exception(e)
end
Expand Down
2 changes: 0 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ class Application < Rails::Application
#{config.root}/lib/lago_eu_vat
#{config.root}/app/views/helpers
#{config.root}/app/support
#{config.root}/app/jobs/concerns
]
config.api_only = true
config.active_job.queue_adapter = :sidekiq
config.autoload_paths << Rails.root.join("app/jobs/concerns")

# Configuration for active record encryption
config.active_record.encryption.primary_key = ENV['ENCRYPTION_PRIMARY_KEY']
Expand Down
3 changes: 1 addition & 2 deletions config/initializers/sentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
if ENV['SENTRY_DSN']
Sentry.init do |config|
config.dsn = ENV['SENTRY_DSN']
config.release = Utils::VersionService.new.version.version.number
config.breadcrumbs_logger = %i[active_support_logger http_logger]
config.traces_sample_rate = ENV['SENTRY_TRACES_SAMPLE_RATE'].to_f || 0
config.traces_sample_rate = 0
config.environment = ENV['SENTRY_ENVIRONMENT'] || Rails.env
end
end
Loading