Moved background jobs to own files.
This commit is contained in:
parent
edecfc5bda
commit
848c526d09
4 changed files with 74 additions and 69 deletions
|
@ -494,7 +494,7 @@ update search index, if configured - will be executed automatically
|
||||||
|
|
||||||
# start background job to transfer data to search index
|
# start background job to transfer data to search index
|
||||||
return if !SearchIndexBackend.enabled?
|
return if !SearchIndexBackend.enabled?
|
||||||
Delayed::Job.enqueue( ApplicationModel::Job.new( self.class.to_s, self.id ) )
|
Delayed::Job.enqueue( ApplicationModel::BackgroundJobSearchIndex.new( self.class.to_s, self.id ) )
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
@ -851,11 +851,4 @@ destory object dependencies, will be executed automatically
|
||||||
def destroy_dependencies
|
def destroy_dependencies
|
||||||
end
|
end
|
||||||
|
|
||||||
# perform background job
|
|
||||||
class ApplicationModel::Job < Struct.new( :object, :o_id )
|
|
||||||
def perform
|
|
||||||
Object.const_get(object).find(o_id).search_index_update_backend
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
11
app/models/application_model/background_job_search_index.rb
Normal file
11
app/models/application_model/background_job_search_index.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# perform background job
|
||||||
|
class ApplicationModel::BackgroundJobSearchIndex
|
||||||
|
def initialize(object, o_id)
|
||||||
|
@object = object
|
||||||
|
@o_id = o_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform
|
||||||
|
Object.const_get(@object).find(@o_id).search_index_update_backend
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,65 +18,6 @@ class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer
|
||||||
return if type['name'] != 'email'
|
return if type['name'] != 'email'
|
||||||
|
|
||||||
# send background job
|
# send background job
|
||||||
Delayed::Job.enqueue( Observer::Ticket::Article::CommunicateEmail::Send.new( record.id ) )
|
Delayed::Job.enqueue( Observer::Ticket::Article::CommunicateEmail::BackgroundJob.new( record.id ) )
|
||||||
end
|
|
||||||
|
|
||||||
class Send < Struct.new( :id )
|
|
||||||
def perform
|
|
||||||
record = Ticket::Article.find( id )
|
|
||||||
|
|
||||||
# build subject
|
|
||||||
ticket = Ticket.lookup( :id => record.ticket_id )
|
|
||||||
subject = ticket.subject_build( record.subject )
|
|
||||||
|
|
||||||
# send email
|
|
||||||
a = Channel::IMAP.new
|
|
||||||
message = a.send(
|
|
||||||
{
|
|
||||||
:message_id => record.message_id,
|
|
||||||
:in_reply_to => record.in_reply_to,
|
|
||||||
:from => record.from,
|
|
||||||
:to => record.to,
|
|
||||||
:cc => record.cc,
|
|
||||||
:subject => subject,
|
|
||||||
:body => record.body,
|
|
||||||
:attachments => record.attachments
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# store mail plain
|
|
||||||
Store.add(
|
|
||||||
:object => 'Ticket::Article::Mail',
|
|
||||||
:o_id => record.id,
|
|
||||||
:data => message.to_s,
|
|
||||||
:filename => "ticket-#{ticket.number}-#{record.id}.eml",
|
|
||||||
:preferences => {},
|
|
||||||
:created_by_id => record.created_by_id,
|
|
||||||
)
|
|
||||||
|
|
||||||
# add history record
|
|
||||||
recipient_list = ''
|
|
||||||
[:to, :cc].each { |key|
|
|
||||||
if record[key] && record[key] != ''
|
|
||||||
if recipient_list != ''
|
|
||||||
recipient_list += ','
|
|
||||||
end
|
|
||||||
recipient_list += record[key]
|
|
||||||
end
|
|
||||||
}
|
|
||||||
if recipient_list != ''
|
|
||||||
History.add(
|
|
||||||
:o_id => record.id,
|
|
||||||
:history_type => 'email',
|
|
||||||
:history_object => 'Ticket::Article',
|
|
||||||
:related_o_id => ticket.id,
|
|
||||||
:related_history_object => 'Ticket',
|
|
||||||
:value_from => record.subject,
|
|
||||||
:value_to => recipient_list,
|
|
||||||
:created_by_id => record.created_by_id,
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
|
||||||
|
def initialize(id)
|
||||||
|
@article_id = id
|
||||||
|
end
|
||||||
|
def perform
|
||||||
|
record = Ticket::Article.find( @article_id )
|
||||||
|
|
||||||
|
# build subject
|
||||||
|
ticket = Ticket.lookup( :id => record.ticket_id )
|
||||||
|
subject = ticket.subject_build( record.subject )
|
||||||
|
|
||||||
|
# send email
|
||||||
|
a = Channel::IMAP.new
|
||||||
|
message = a.send(
|
||||||
|
{
|
||||||
|
:message_id => record.message_id,
|
||||||
|
:in_reply_to => record.in_reply_to,
|
||||||
|
:from => record.from,
|
||||||
|
:to => record.to,
|
||||||
|
:cc => record.cc,
|
||||||
|
:subject => subject,
|
||||||
|
:body => record.body,
|
||||||
|
:attachments => record.attachments
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# store mail plain
|
||||||
|
Store.add(
|
||||||
|
:object => 'Ticket::Article::Mail',
|
||||||
|
:o_id => record.id,
|
||||||
|
:data => message.to_s,
|
||||||
|
:filename => "ticket-#{ticket.number}-#{record.id}.eml",
|
||||||
|
:preferences => {},
|
||||||
|
:created_by_id => record.created_by_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
# add history record
|
||||||
|
recipient_list = ''
|
||||||
|
[:to, :cc].each { |key|
|
||||||
|
if record[key] && record[key] != ''
|
||||||
|
if recipient_list != ''
|
||||||
|
recipient_list += ','
|
||||||
|
end
|
||||||
|
recipient_list += record[key]
|
||||||
|
end
|
||||||
|
}
|
||||||
|
if recipient_list != ''
|
||||||
|
History.add(
|
||||||
|
:o_id => record.id,
|
||||||
|
:history_type => 'email',
|
||||||
|
:history_object => 'Ticket::Article',
|
||||||
|
:related_o_id => ticket.id,
|
||||||
|
:related_history_object => 'Ticket',
|
||||||
|
:value_from => record.subject,
|
||||||
|
:value_to => recipient_list,
|
||||||
|
:created_by_id => record.created_by_id,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue