jobs: migrate aliases/implications to ActiveJob.
This commit is contained in:
8
app/jobs/process_tag_alias_job.rb
Normal file
8
app/jobs/process_tag_alias_job.rb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
class ProcessTagAliasJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
queue_with_priority 20
|
||||||
|
|
||||||
|
def perform(tag_alias, update_topic: true)
|
||||||
|
tag_alias.process!(update_topic: update_topic)
|
||||||
|
end
|
||||||
|
end
|
||||||
8
app/jobs/process_tag_implication_job.rb
Normal file
8
app/jobs/process_tag_implication_job.rb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
class ProcessTagImplicationJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
queue_with_priority 20
|
||||||
|
|
||||||
|
def perform(tag_implication, update_topic: true)
|
||||||
|
tag_implication.process!(update_topic: update_topic)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6,11 +6,9 @@ class TagAlias < TagRelationship
|
|||||||
validate :mininum_antecedent_count, on: :create, unless: :skip_secondary_validations
|
validate :mininum_antecedent_count, on: :create, unless: :skip_secondary_validations
|
||||||
|
|
||||||
module ApprovalMethods
|
module ApprovalMethods
|
||||||
def approve!(update_topic: true, approver: CurrentUser.user)
|
def approve!(approver: CurrentUser.user, update_topic: true)
|
||||||
CurrentUser.scoped(approver) do
|
update(approver: approver, status: "queued")
|
||||||
update(status: "queued", approver_id: approver.id)
|
ProcessTagAliasJob.perform_later(self, update_topic: update_topic)
|
||||||
delay(:queue => "default").process!(update_topic: update_topic)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -163,8 +163,8 @@ class TagImplication < TagRelationship
|
|||||||
end
|
end
|
||||||
|
|
||||||
def approve!(approver: CurrentUser.user, update_topic: true)
|
def approve!(approver: CurrentUser.user, update_topic: true)
|
||||||
update(status: "queued", approver_id: approver.id)
|
update(approver: approver, status: "queued")
|
||||||
delay(:queue => "default").process!(update_topic: update_topic)
|
ProcessTagImplicationJob.perform_later(self, update_topic: update_topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reject!(update_topic: true)
|
def reject!(update_topic: true)
|
||||||
|
|||||||
@@ -245,8 +245,11 @@ class TagImplicationTest < ActiveSupport::TestCase
|
|||||||
p1 = FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
p1 = FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
||||||
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
ti1 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||||
ti2 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "yyy")
|
ti2 = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "yyy")
|
||||||
ti1.approve!
|
|
||||||
ti2.approve!
|
perform_enqueued_jobs do
|
||||||
|
ti1.approve!
|
||||||
|
ti2.approve!
|
||||||
|
end
|
||||||
|
|
||||||
assert_equal("aaa bbb ccc xxx yyy", p1.reload.tag_string)
|
assert_equal("aaa bbb ccc xxx yyy", p1.reload.tag_string)
|
||||||
end
|
end
|
||||||
@@ -261,12 +264,13 @@ class TagImplicationTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
should "update the topic when processed" do
|
should "update the topic when processed" do
|
||||||
assert_difference("ForumPost.count") do
|
assert_difference("ForumPost.count") do
|
||||||
@implication.approve!
|
perform_enqueued_jobs do
|
||||||
|
@implication.approve!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@post.reload
|
|
||||||
@topic.reload
|
assert_match(/The tag implication .* has been approved/, @post.reload.body)
|
||||||
assert_match(/The tag implication .* has been approved/, @post.body)
|
assert_equal("[APPROVED] Tag implication: aaa -> bbb", @topic.reload.title)
|
||||||
assert_equal("[APPROVED] Tag implication: aaa -> bbb", @topic.title)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "update the topic when rejected" do
|
should "update the topic when rejected" do
|
||||||
|
|||||||
Reference in New Issue
Block a user