Change Webhook::DestroyJob to Wehook::DestroyWorker and move to sidekiq (#5424) [deploy]
This commit is contained in:
parent
cf88f93874
commit
1ed6aca54a
5 changed files with 16 additions and 13 deletions
|
|
@ -10,7 +10,7 @@ module Oauth
|
|||
# the access token model.
|
||||
if authorized?
|
||||
revoke_token
|
||||
Webhook::DestroyJob.perform_later(user_id: token.resource_owner_id, application_id: token.application_id)
|
||||
Webhook::DestroyWorker.perform_async(token.resource_owner_id, token.application_id)
|
||||
render json: {}, status: :ok
|
||||
else
|
||||
error_description = I18n.t(:unauthorized, scope: %i[doorkeeper errors messages revoke])
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
module Webhook
|
||||
class DestroyJob < ApplicationJob
|
||||
queue_as :webhook_destroy
|
||||
|
||||
def perform(user_id:, application_id:)
|
||||
Webhook::Endpoint.where(user_id: user_id, oauth_application_id: application_id).destroy_all
|
||||
end
|
||||
end
|
||||
end
|
||||
11
app/workers/webhook/destroy_worker.rb
Normal file
11
app/workers/webhook/destroy_worker.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module Webhook
|
||||
class DestroyWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: :low_priority, retry: 10
|
||||
|
||||
def perform(user_id, application_id)
|
||||
Webhook::Endpoint.where(user_id: user_id, oauth_application_id: application_id).destroy_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -19,7 +19,7 @@ RSpec.describe "Oauth::Tokens", type: :request do
|
|||
user2_webhook = create(:webhook_endpoint, oauth_application: oauth_app)
|
||||
another_app_webhook = create(:webhook_endpoint)
|
||||
|
||||
perform_enqueued_jobs do
|
||||
sidekiq_perform_enqueued_jobs do
|
||||
post oauth_revoke_path, params: { token: access_token.token }
|
||||
end
|
||||
expect(Webhook::Endpoint.find_by(id: user_webhook.id)).to be_nil
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Webhook::DestroyJob, type: :job do
|
||||
RSpec.describe Webhook::DestroyWorker, type: :worker do
|
||||
let(:user) { create(:user) }
|
||||
let(:oauth_app) { create(:application) }
|
||||
let!(:webhook_endpoint) { create(:webhook_endpoint, user: user, oauth_application: oauth_app) }
|
||||
let!(:other_webhook_endpoint) { create(:webhook_endpoint, oauth_application: oauth_app) }
|
||||
let(:worker) { subject }
|
||||
|
||||
describe "#perform_now" do
|
||||
it "destrous webhook by user_id and app_id" do
|
||||
described_class.perform_now(user_id: user.id, application_id: oauth_app.id)
|
||||
worker.perform(user.id, oauth_app.id)
|
||||
expect(Webhook::Endpoint.find_by(id: webhook_endpoint.id)).to be_nil
|
||||
expect(other_webhook_endpoint.reload).to be_present
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue