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

Add a rake task to clean expired access tokens #114

Open
hoangmirs opened this issue Nov 20, 2023 · 1 comment
Open

Add a rake task to clean expired access tokens #114

hoangmirs opened this issue Nov 20, 2023 · 1 comment

Comments

@hoangmirs
Copy link
Contributor

Why

  • We're using Heroku Postgres - Mini which has the limitation of 10k records
  • Recently, the records have increased so quickly
  • We should add a task to clean the token table and run it everyday
namespace :token do
  desc "Clean expired tokens"
  task clean: :environment do
    delete_before = 1.days.ago
    expire = [
      "(revoked_at IS NOT NULL AND revoked_at < :delete_before) OR " +
      "(expires_in IS NOT NULL AND (created_at + expires_in * INTERVAL '1 second') < :delete_before)",
      { delete_before: delete_before }
    ]

    Doorkeeper::AccessToken.where(expire).delete_all
  end
end

Who Benefits?

Maintainers

@olivierobert
Copy link
Contributor

One way to run such a task without setting up anything additional on Heroku (see: https://devcenter.heroku.com/articles/scheduler) is to use a GitHub Actions workflow with the trigger schedule: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule.

In both cases, there is a cost of running it. However, on GH Actions, it would be within our free tier of 3,000 minutes and by using a workflow, it can be trigged manually when needed.

IMO I doubt it would be needed to be run daily. Weekly might be sufficient 💡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants