FIX: Ensure that we cancel any timeout jobs when terminating a track.
This commit is contained in:
parent
3621647fb5
commit
30f2758404
|
@ -77,5 +77,20 @@ module DiscourseNarrativeBot
|
|||
topic.pm_with_non_human_user? &&
|
||||
topic.topic_allowed_users.where(user_id: -2).exists?
|
||||
end
|
||||
|
||||
def cancel_timeout_job(user)
|
||||
Jobs.cancel_scheduled_job(:narrative_timeout, user_id: user.id, klass: self.class.to_s)
|
||||
end
|
||||
|
||||
def enqueue_timeout_job(user)
|
||||
return if Rails.env.test?
|
||||
|
||||
cancel_timeout_job(user)
|
||||
|
||||
Jobs.enqueue_in(TIMEOUT_DURATION, :narrative_timeout,
|
||||
user_id: user.id,
|
||||
klass: self.class.to_s
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -163,21 +163,6 @@ module DiscourseNarrativeBot
|
|||
topic_id == @data[:topic_id]
|
||||
end
|
||||
|
||||
def cancel_timeout_job(user)
|
||||
Jobs.cancel_scheduled_job(:narrative_timeout, user_id: user.id, klass: self.class.to_s)
|
||||
end
|
||||
|
||||
def enqueue_timeout_job(user)
|
||||
return if Rails.env.test?
|
||||
|
||||
cancel_timeout_job(user)
|
||||
|
||||
Jobs.enqueue_in(TIMEOUT_DURATION, :narrative_timeout,
|
||||
user_id: user.id,
|
||||
klass: self.class.to_s
|
||||
)
|
||||
end
|
||||
|
||||
def not_implemented
|
||||
raise 'Not implemented.'
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ module DiscourseNarrativeBot
|
|||
klass = (data[:track] || NewUserNarrative.to_s).constantize
|
||||
|
||||
if is_reply && like_user_post
|
||||
Store.set(@user.id, data.merge!(state: nil, topic_id: nil))
|
||||
terminate_track(data)
|
||||
elsif state&.to_sym == :end && is_reply
|
||||
bot_commands(bot_mentioned?) || generic_replies(klass.reset_trigger)
|
||||
elsif is_reply
|
||||
|
@ -253,5 +253,10 @@ module DiscourseNarrativeBot
|
|||
!SiteSetting.discourse_narrative_bot_disable_public_replies &&
|
||||
(bot_mentioned? || reply_to_bot_post?(@post))
|
||||
end
|
||||
|
||||
def terminate_track(data)
|
||||
Store.set(@user.id, data.merge!(state: nil, topic_id: nil))
|
||||
cancel_timeout_job(@user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -127,9 +127,6 @@ describe DiscourseNarrativeBot::TrackSelector do
|
|||
|
||||
expect(post_action.post).to eq(post)
|
||||
expect(post_action.post_action_type_id).to eq(PostActionType.types[:like])
|
||||
|
||||
post = Post.last
|
||||
|
||||
expect(Post.last).to eq(post)
|
||||
|
||||
expect(DiscourseNarrativeBot::NewUserNarrative.new.get_data(user)['state'])
|
||||
|
|
Loading…
Reference in New Issue