diff --git a/app/controllers/oauth/tokens_controller.rb b/app/controllers/oauth/tokens_controller.rb index 23bb65356..9bc7f4371 100644 --- a/app/controllers/oauth/tokens_controller.rb +++ b/app/controllers/oauth/tokens_controller.rb @@ -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]) diff --git a/app/jobs/webhook/destroy_job.rb b/app/jobs/webhook/destroy_job.rb deleted file mode 100644 index c5d232265..000000000 --- a/app/jobs/webhook/destroy_job.rb +++ /dev/null @@ -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 diff --git a/app/workers/webhook/destroy_worker.rb b/app/workers/webhook/destroy_worker.rb new file mode 100644 index 000000000..e008a54e5 --- /dev/null +++ b/app/workers/webhook/destroy_worker.rb @@ -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 diff --git a/spec/requests/oauth/tokens_spec.rb b/spec/requests/oauth/tokens_spec.rb index 99ec4032d..c1d604f7a 100644 --- a/spec/requests/oauth/tokens_spec.rb +++ b/spec/requests/oauth/tokens_spec.rb @@ -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 diff --git a/spec/jobs/webhook/destroy_job_spec.rb b/spec/workers/webhook/destroy_worker_spec.rb similarity index 79% rename from spec/jobs/webhook/destroy_job_spec.rb rename to spec/workers/webhook/destroy_worker_spec.rb index 5e1308796..3633375be 100644 --- a/spec/jobs/webhook/destroy_job_spec.rb +++ b/spec/workers/webhook/destroy_worker_spec.rb @@ -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