Added background job to rebuild signature for user on new article.

This commit is contained in:
Rolf Schmidt 2015-10-08 11:05:39 +02:00
parent f807d10dd3
commit da983a6e43
3 changed files with 37 additions and 9 deletions

View file

@ -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) 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
end end

View file

@ -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

View file

@ -158,16 +158,33 @@ returns
def self.rebuild_all_user def self.rebuild_all_user
User.select('id').where(active: true).each {|local_user| User.select('id').where(active: true).each {|local_user|
rebuild_user(local_user.id)
}
true
end
signature_detection = by_user_id(local_user.id) =begin
next if !signature_detection
user = User.find(local_user.id) rebuild signature for user
next if user.preferences[:signature_detection] == signature_detection
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.preferences[:signature_detection] = signature_detection
user.save user.save
}
true true
end end