Added background job to rebuild signature for user on new article.
This commit is contained in:
parent
f807d10dd3
commit
da983a6e43
3 changed files with 37 additions and 9 deletions
|
@ -25,5 +25,7 @@ class Observer::Ticket::Article::EmailSignatureDetection < ActiveRecord::Observe
|
|||
|
||||
record.preferences[:signature_detection] = SignatureDetection.find_signature_line(user.preferences[:signature_detection], record.body)
|
||||
|
||||
# add queue job to update current signature of user id
|
||||
Delayed::Job.enqueue( Observer::Ticket::Article::EmailSignatureDetection::BackgroundJob.new( record.created_by_id ) )
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class Observer::Ticket::Article::EmailSignatureDetection::BackgroundJob
|
||||
def initialize(id)
|
||||
@user_id = id
|
||||
end
|
||||
|
||||
def perform
|
||||
SignatureDetection.rebuild_user(@user_id)
|
||||
end
|
||||
end
|
|
@ -158,21 +158,38 @@ returns
|
|||
def self.rebuild_all_user
|
||||
|
||||
User.select('id').where(active: true).each {|local_user|
|
||||
|
||||
signature_detection = by_user_id(local_user.id)
|
||||
next if !signature_detection
|
||||
|
||||
user = User.find(local_user.id)
|
||||
next if user.preferences[:signature_detection] == signature_detection
|
||||
|
||||
user.preferences[:signature_detection] = signature_detection
|
||||
user.save
|
||||
rebuild_user(local_user.id)
|
||||
}
|
||||
true
|
||||
end
|
||||
|
||||
=begin
|
||||
|
||||
rebuild signature for user
|
||||
|
||||
SignatureDetection.rebuild_user
|
||||
|
||||
returns
|
||||
|
||||
true/false
|
||||
|
||||
=end
|
||||
|
||||
def self.rebuild_user(user_id)
|
||||
signature_detection = by_user_id(user_id)
|
||||
return if !signature_detection
|
||||
|
||||
user = User.find(user_id)
|
||||
return if user.preferences[:signature_detection] == signature_detection
|
||||
|
||||
user.preferences[:signature_detection] = signature_detection
|
||||
user.save
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
=begin
|
||||
|
||||
rebuild signature for all articles
|
||||
|
||||
SignatureDetection.rebuild_all_articles
|
||||
|
|
Loading…
Reference in a new issue