Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Ivlev
bugzilla
Commits
e9f07c7e
Commit
e9f07c7e
authored
Jul 31, 2013
by
Byron Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 877078: shift bugmail generation to the jobqueue
r=sgreen, a=sgreen
parent
5d5597bb
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
164 additions
and
28 deletions
+164
-28
BugMail.pm
Bugzilla/BugMail.pm
+83
-16
BugMail.pm
Bugzilla/Job/BugMail.pm
+31
-0
Mailer.pm
Bugzilla/Job/Mailer.pm
+0
-10
JobQueue.pm
Bugzilla/JobQueue.pm
+1
-0
Object.pm
Bugzilla/Object.pm
+48
-2
011pod.t
t/011pod.t
+1
-0
No files found.
Bugzilla/BugMail.pm
View file @
e9f07c7e
...
@@ -23,6 +23,7 @@ use Date::Parse;
...
@@ -23,6 +23,7 @@ use Date::Parse;
use
Date::
Format
;
use
Date::
Format
;
use
Scalar::
Util
qw(blessed)
;
use
Scalar::
Util
qw(blessed)
;
use
List::
MoreUtils
qw(uniq)
;
use
List::
MoreUtils
qw(uniq)
;
use
Storable
qw(dclone)
;
use
constant
BIT_DIRECT
=>
1
;
use
constant
BIT_DIRECT
=>
1
;
use
constant
BIT_WATCHING
=>
2
;
use
constant
BIT_WATCHING
=>
2
;
...
@@ -339,31 +340,76 @@ sub sendMail {
...
@@ -339,31 +340,76 @@ sub sendMail {
$bugmailtype
=
"dep_changed"
if
$dep_only
;
$bugmailtype
=
"dep_changed"
if
$dep_only
;
my
$vars
=
{
my
$vars
=
{
date
=>
$date
,
date
=>
$date
,
to_user
=>
$user
,
to_user
=>
$user
,
bug
=>
$bug
,
bug
=>
$bug
,
reasons
=>
\
@reasons
,
reasons
=>
\
@reasons
,
reasons_watch
=>
\
@reasons_watch
,
reasons_watch
=>
\
@reasons_watch
,
reasonsheader
=>
join
(
" "
,
@headerrel
),
reasonsheader
=>
join
(
" "
,
@headerrel
),
reasonswatchheader
=>
join
(
" "
,
@watchingrel
),
reasonswatchheader
=>
join
(
" "
,
@watchingrel
),
changer
=>
$changer
,
changer
=>
$changer
,
diffs
=>
\
@display_diffs
,
diffs
=>
\
@display_diffs
,
changedfields
=>
\
@changedfields
,
changedfields
=>
\
@changedfields
,
new_comments
=>
\
@send_comments
,
new_comments
=>
\
@send_comments
,
threadingmarker
=>
build_thread_marker
(
$bug
->
id
,
$user
->
id
,
!
$bug
->
lastdiffed
),
threadingmarker
=>
build_thread_marker
(
$bug
->
id
,
$user
->
id
,
!
$bug
->
lastdiffed
),
bugmailtype
=>
$bugmailtype
bugmailtype
=>
$bugmailtype
,
};
};
my
$msg
=
_generate_bugmail
(
$user
,
$vars
);
if
(
Bugzilla
->
params
->
{
'use_mailer_queue'
})
{
MessageToMTA
(
$msg
);
enqueue
(
$vars
);
}
else
{
MessageToMTA
(
_generate_bugmail
(
$vars
));
}
return
1
;
return
1
;
}
}
sub
enqueue
{
my
(
$vars
)
=
@_
;
# we need to flatten all objects to a hash before pushing to the job queue.
# the hashes need to be inflated in the dequeue method.
$vars
->
{
bug
}
=
_flatten_object
(
$vars
->
{
bug
});
$vars
->
{
to_user
}
=
$vars
->
{
to_user
}
->
flatten_to_hash
;
$vars
->
{
changer
}
=
_flatten_object
(
$vars
->
{
changer
});
$vars
->
{
new_comments
}
=
[
map
{
_flatten_object
(
$_
)
}
@
{
$vars
->
{
new_comments
}
}
];
foreach
my
$diff
(
@
{
$vars
->
{
diffs
}
})
{
$diff
->
{
who
}
=
_flatten_object
(
$diff
->
{
who
});
}
Bugzilla
->
job_queue
->
insert
(
'bug_mail'
,
{
vars
=>
$vars
});
}
sub
dequeue
{
my
(
$payload
)
=
@_
;
# clone the payload so we can modify it without impacting TheSchwartz's
# ability to process the job when we've finished
my
$vars
=
dclone
(
$payload
);
# inflate objects
$vars
->
{
bug
}
=
Bugzilla::
Bug
->
new_from_hash
(
$vars
->
{
bug
});
$vars
->
{
to_user
}
=
Bugzilla::
User
->
new_from_hash
(
$vars
->
{
to_user
});
$vars
->
{
changer
}
=
Bugzilla::
User
->
new_from_hash
(
$vars
->
{
changer
});
$vars
->
{
new_comments
}
=
[
map
{
Bugzilla::
Comment
->
new_from_hash
(
$_
)
}
@
{
$vars
->
{
new_comments
}
}
];
foreach
my
$diff
(
@
{
$vars
->
{
diffs
}
})
{
$diff
->
{
who
}
=
Bugzilla::
User
->
new_from_hash
(
$diff
->
{
who
});
}
# generate bugmail and send
MessageToMTA
(
_generate_bugmail
(
$vars
),
1
);
}
sub
_flatten_object
{
my
(
$object
)
=
@_
;
# nothing to do if it's already flattened
return
$object
unless
blessed
(
$object
);
# the same objects are used for each recipient, so cache the flattened hash
my
$cache
=
Bugzilla
->
request_cache
->
{
bugmail_flat_objects
}
||=
{};
my
$key
=
blessed
(
$object
)
.
'-'
.
$object
->
id
;
return
$cache
->
{
$key
}
||=
$object
->
flatten_to_hash
;
}
sub
_generate_bugmail
{
sub
_generate_bugmail
{
my
(
$user
,
$vars
)
=
@_
;
my
(
$vars
)
=
@_
;
my
$user
=
$vars
->
{
to_user
};
my
$template
=
Bugzilla
->
template_inner
(
$user
->
setting
(
'lang'
));
my
$template
=
Bugzilla
->
template_inner
(
$user
->
setting
(
'lang'
));
my
(
$msg_text
,
$msg_html
,
$msg_header
);
my
(
$msg_text
,
$msg_html
,
$msg_header
);
$template
->
process
(
"email/bugmail-header.txt.tmpl"
,
$vars
,
\
$msg_header
)
$template
->
process
(
"email/bugmail-header.txt.tmpl"
,
$vars
,
\
$msg_header
)
||
ThrowTemplateError
(
$template
->
error
());
||
ThrowTemplateError
(
$template
->
error
());
$template
->
process
(
"email/bugmail.txt.tmpl"
,
$vars
,
\
$msg_text
)
$template
->
process
(
"email/bugmail.txt.tmpl"
,
$vars
,
\
$msg_text
)
...
@@ -507,6 +553,27 @@ sub _get_new_bugmail_fields {
...
@@ -507,6 +553,27 @@ sub _get_new_bugmail_fields {
1
;
1
;
=
head1
NAME
BugMail
-
Routines
to
generate
email
notifications
when
a
bug
is
created
or
modified
.
=
head1
METHODS
=
over
4
=
item
C
<
enqueue
>
Serialises
the
variables
required
to
generate
bugmail
and
pushes
the
result
to
the
job
-
queue
for
processing
by
TheSchwartz
.
=
item
C
<
dequeue
>
When
given
serialised
variables
from
the
job
-
queue
,
recreates
the
objects
from
the
flattened
hashes
,
generates
the
bugmail
,
and
sends
it
.
=
back
=
head1
B
<
Methods
in
need
of
POD
>
=
head1
B
<
Methods
in
need
of
POD
>
=
over
=
over
...
...
Bugzilla/Job/BugMail.pm
0 → 100644
View file @
e9f07c7e
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
package
Bugzilla::Job::
BugMail
;
use
5.10.1
;
use
strict
;
use
Bugzilla::
BugMail
;
BEGIN
{
eval
"use parent qw(Bugzilla::Job::Mailer)"
;
}
sub
work
{
my
(
$class
,
$job
)
=
@_
;
my
$success
=
eval
{
Bugzilla::BugMail::
dequeue
(
$job
->
arg
->
{
vars
});
1
;
};
if
(
!
$success
)
{
$job
->
failed
(
$@
);
undef
$@
;
}
else
{
$job
->
completed
;
}
}
1
;
Bugzilla/Job/Mailer.pm
View file @
e9f07c7e
...
@@ -43,13 +43,3 @@ sub work {
...
@@ -43,13 +43,3 @@ sub work {
}
}
1
;
1
;
=
head1
B
<
Methods
in
need
of
POD
>
=
over
=
item
retry_delay
=
item
work
=
back
Bugzilla/JobQueue.pm
View file @
e9f07c7e
...
@@ -22,6 +22,7 @@ use fields qw(_worker_pidfile);
...
@@ -22,6 +22,7 @@ use fields qw(_worker_pidfile);
# If you add new types of jobs, you should add a mapping here.
# If you add new types of jobs, you should add a mapping here.
use
constant
JOB_MAP
=>
{
use
constant
JOB_MAP
=>
{
send_mail
=>
'Bugzilla::Job::Mailer'
,
send_mail
=>
'Bugzilla::Job::Mailer'
,
bug_mail
=>
'Bugzilla::Job::BugMail'
,
};
};
# Without a driver cache TheSchwartz opens a new database connection
# Without a driver cache TheSchwartz opens a new database connection
...
...
Bugzilla/Object.pm
View file @
e9f07c7e
...
@@ -113,7 +113,10 @@ sub _init {
...
@@ -113,7 +113,10 @@ sub _init {
"SELECT $columns FROM $table WHERE $condition"
,
undef
,
@values
);
"SELECT $columns FROM $table WHERE $condition"
,
undef
,
@values
);
}
}
$class
->
_cache_set
(
$param
,
$object
)
if
$object
;
if
(
$object
)
{
$class
->
_serialisation_keys
(
$object
);
$class
->
_cache_set
(
$param
,
$object
);
}
return
$object
;
return
$object
;
}
}
...
@@ -144,6 +147,15 @@ sub cache_key {
...
@@ -144,6 +147,15 @@ sub cache_key {
}
}
}
}
# To support serialisation, we need to capture the keys in an object's default
# hashref.
sub
_serialisation_keys
{
my
(
$class
,
$object
)
=
@_
;
my
$cache
=
Bugzilla
->
request_cache
->
{
serialisation_keys
}
||=
{};
$cache
->
{
$class
}
=
[
keys
%
$object
]
if
$object
;
return
@
{
$cache
->
{
$class
}
};
}
sub
check
{
sub
check
{
my
(
$invocant
,
$param
)
=
@_
;
my
(
$invocant
,
$param
)
=
@_
;
my
$class
=
ref
(
$invocant
)
||
$invocant
;
my
$class
=
ref
(
$invocant
)
||
$invocant
;
...
@@ -199,6 +211,14 @@ sub new_from_list {
...
@@ -199,6 +211,14 @@ sub new_from_list {
return
match
(
$invocant
,
{
$id_field
=>
\
@detainted_ids
});
return
match
(
$invocant
,
{
$id_field
=>
\
@detainted_ids
});
}
}
sub
new_from_hash
{
my
$invocant
=
shift
;
my
$class
=
ref
(
$invocant
)
||
$invocant
;
my
$object
=
shift
;
bless
(
$object
,
$class
);
return
$object
;
}
# Note: Future extensions to this could be:
# Note: Future extensions to this could be:
# * Add a MATCH_JOIN constant so that we can join against
# * Add a MATCH_JOIN constant so that we can join against
# certain other tables for the WHERE criteria.
# certain other tables for the WHERE criteria.
...
@@ -297,7 +317,8 @@ sub _do_list_select {
...
@@ -297,7 +317,8 @@ sub _do_list_select {
my
@untainted
=
@
{
$values
||
[]
};
my
@untainted
=
@
{
$values
||
[]
};
trick_taint
(
$_
)
foreach
@untainted
;
trick_taint
(
$_
)
foreach
@untainted
;
my
$objects
=
$dbh
->
selectall_arrayref
(
$sql
,
{
Slice
=>
{}},
@untainted
);
my
$objects
=
$dbh
->
selectall_arrayref
(
$sql
,
{
Slice
=>
{}},
@untainted
);
bless
(
$_
,
$class
)
foreach
@$objects
;
$class
->
_serialisation_keys
(
$objects
->
[
0
])
if
@$objects
;
bless
(
$_
,
$class
)
foreach
@$objects
;
return
$objects
return
$objects
}
}
...
@@ -474,6 +495,13 @@ sub audit_log {
...
@@ -474,6 +495,13 @@ sub audit_log {
}
}
}
}
sub
flatten_to_hash
{
my
$self
=
shift
;
my
$class
=
blessed
(
$self
);
my
%
hash
=
map
{
$_
=>
$self
->
{
$_
}
}
$class
->
_serialisation_keys
;
return
\%
hash
;
}
###############################
###############################
#### Subroutines ######
#### Subroutines ######
###############################
###############################
...
@@ -1040,6 +1068,13 @@ template.
...
@@ -1040,6 +1068,13 @@ template.
Returns: A reference to an array of objects.
Returns: A reference to an array of objects.
=item C<new_from_hash($hashref)>
Description: Create an object from the given hash.
Params: $hashref - A reference to a hash which was created by
flatten_to_hash.
=item C<match>
=item C<match>
=over
=over
...
@@ -1277,6 +1312,17 @@ that should be passed to the C<set_> function that is called.
...
@@ -1277,6 +1312,17 @@ that should be passed to the C<set_> function that is called.
=back
=back
=head2 Simple Methods
=over
=item C<flatten_to_hash>
Returns a hashref suitable for serialisation and re-inflation with C<new_from_hash>.
=back
=head2 Simple Validators
=head2 Simple Validators
You can use these in your subclass L</VALIDATORS> or L</UPDATE_VALIDATORS>.
You can use these in your subclass L</VALIDATORS> or L</UPDATE_VALIDATORS>.
...
...
t/011pod.t
View file @
e9f07c7e
...
@@ -43,6 +43,7 @@ use constant MODULE_WHITELIST => qw(
...
@@ -43,6 +43,7 @@ use constant MODULE_WHITELIST => qw(
Bugzilla::Auth::Verify::
Bugzilla::Auth::Verify::
Bugzilla::BugUrl::
Bugzilla::BugUrl::
Bugzilla::Config::
Bugzilla::Config::
Bugzilla::Job::
);
);
# Capture the TESTOUT from Test::More or Test::Builder for printing errors.
# Capture the TESTOUT from Test::More or Test::Builder for printing errors.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment