about summary refs log tree commit diff
path: root/app/lib/access_token_extension.rb
blob: 3e184e7753032dd50813170cca6ab3b43ff508d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# frozen_string_literal: true

module AccessTokenExtension
  extend ActiveSupport::Concern

  included do
    after_commit :push_to_streaming_api
  end

  def revoke(clock = Time)
    update(revoked_at: clock.now.utc)
  end

  def push_to_streaming_api
    Redis.current.publish("timeline:access_token:#{id}", Oj.dump(event: :kill)) if revoked? || destroyed?
  end
end