Class: Ocpp::Rails::CleanupAuthorizationsJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/ocpp/rails/cleanup_authorizations_job.rb

Instance Method Summary collapse

Instance Method Details

#performObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/jobs/ocpp/rails/cleanup_authorizations_job.rb', line 6

def perform
  unless Ocpp::Rails.configuration.authorization_cleanup_enabled
    ::Rails.logger.info("Authorization cleanup disabled, skipping")
    return
  end

  begin
    retention_days = Ocpp::Rails.configuration.authorization_retention_days
    deleted_count = Ocpp::Rails::Authorization.older_than(retention_days).delete_all

    ::Rails.logger.info("Deleted #{deleted_count} Authorization records older than #{retention_days} days")
  rescue => error
    ::Rails.logger.error("Authorization cleanup failed: #{error.message}")
  ensure
    # Re-enqueue for next run (24 hours later) only if cleanup is enabled
    if Ocpp::Rails.configuration.authorization_cleanup_enabled
      self.class.set(wait: 24.hours).perform_later
    end
  end
end