DEV: Move commit comment syncing work to SideKiq

DEV: Move commit comment syncing work to SideKiq

… to prevent webhook timeouts.

diff --git a/app/controllers/discourse_code_review/code_review_controller.rb b/app/controllers/discourse_code_review/code_review_controller.rb
index 65f2e18..4f7e289 100644
--- a/app/controllers/discourse_code_review/code_review_controller.rb
+++ b/app/controllers/discourse_code_review/code_review_controller.rb
@@ -35,14 +35,13 @@ module DiscourseCodeReview
       repo_name = repo["full_name"] if repo
 
       if type == "commit_comment"
-        client = DiscourseCodeReview.octokit_client
-        github_commit_querier = DiscourseCodeReview.github_commit_querier
-        repo = GithubRepo.new(repo_name, client, github_commit_querier)
-        importer = Importer.new(repo)
-
         commit_sha = params["comment"]["commit_id"]
 
-        importer.sync_commit_sha(commit_sha)
+        ::Jobs.enqueue(
+          :code_review_sync_commit_comments,
+          repo_name: repo_name,
+          commit_sha: commit_sha,
+        )
       end
 
       if type == "push"
diff --git a/app/jobs/regular/code_review_sync_commit_comments.rb b/app/jobs/regular/code_review_sync_commit_comments.rb
new file mode 100644
index 0000000..e579b8a
--- /dev/null
+++ b/app/jobs/regular/code_review_sync_commit_comments.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module Jobs
+  class CodeReviewSyncCommitComments < ::Jobs::Base
+    def execute(args)
+      repo_name, commit_sha = args.values_at(:repo_name, :commit_sha)
+
+      unless repo_name.kind_of?(String)
+        raise Discourse::InvalidParameters.new(:repo_name)
+      end
+
+      unless commit_sha.kind_of?(String)
+        raise Discourse::InvalidParameters.new(:commit_sha)
+      end
+
+      client = DiscourseCodeReview.octokit_client
+      github_commit_querier = DiscourseCodeReview.github_commit_querier
+      repo = DiscourseCodeReview::GithubRepo.new(repo_name, client, github_commit_querier)
+      importer = DiscourseCodeReview::Importer.new(repo)
+
+      importer.sync_commit_sha(commit_sha)
+    end
+  end
+end
diff --git a/plugin.rb b/plugin.rb
index 5a28eb9..662d6b6 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -167,6 +167,7 @@ after_initialize do
   require File.expand_path("../app/controllers/discourse_code_review/repos_controller.rb", __FILE__)
   require File.expand_path("../app/controllers/discourse_code_review/admin_code_review_controller.rb", __FILE__)
   require File.expand_path("../app/jobs/regular/code_review_sync_commits", __FILE__)
+  require File.expand_path("../app/jobs/regular/code_review_sync_commit_comments", __FILE__)
   require File.expand_path("../lib/enumerators", __FILE__)
   require File.expand_path("../lib/typed_data", __FILE__)
   require File.expand_path("../lib/graphql_client", __FILE__)

GitHub sha: 47168f95

1 Like