[Patchew-devel] [PATCH v2 09/12] maintainer: Add MessageQueued and MessageDropping events

Fam Zheng posted 12 patches 5 years, 10 months ago
[Patchew-devel] [PATCH v2 09/12] maintainer: Add MessageQueued and MessageDropping events
Posted by Fam Zheng 5 years, 10 months ago
From: Fam Zheng <famz@redhat.com>

These events are not used internally but is an interesting point where
users can receive notifications when the watched queue is updated.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 mods/maintainer.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/mods/maintainer.py b/mods/maintainer.py
index d342748..6b09057 100644
--- a/mods/maintainer.py
+++ b/mods/maintainer.py
@@ -16,7 +16,7 @@ from mod import PatchewModule
 from api.models import Message, Queue, WatchedQuery
 from django.shortcuts import render
 from api.search import SearchEngine
-from event import register_handler
+from event import declare_event, register_handler, emit_event
 
 class MaintainerModule(PatchewModule):
     """ Project maintainer related tasks """
@@ -25,14 +25,24 @@ class MaintainerModule(PatchewModule):
 
     def __init__(self):
         register_handler("ResultUpdate", self.on_result_update)
+        declare_event("MessageQueued",
+                      message="Message added",
+                      queue="The updated queue")
+        declare_event("MessageDropping",
+                      message="Message to be dropped",
+                      queue="Message is about to be dropping from a queue")
 
     def _add_to_queue(self, user, m, queue):
         for x in [m] + list(m.get_patches()):
-            Queue.objects.get_or_create(user=user, message=x, name=queue)
+            q, created = Queue.objects.get_or_create(user=user, message=x, name=queue)
+            if created:
+                emit_event("MessageQueued", message=x, queue=q)
 
     def _drop_from_queue(self, user, m, queue):
         query = Queue.objects.filter(user=user, message__in=m.get_patches() + [m],
                                      name=queue)
+        for q in query:
+            emit_event("MessageDropping", message=q.message, queue=q)
         q.delete()
 
     def _update_watch_queue(self, series):
-- 
2.17.2


_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH v2 09/12] maintainer: Add MessageQueued and MessageDropping events
Posted by Paolo Bonzini 5 years, 10 months ago
Two small changes I'd like here:

On 28/11/18 15:35, Fam Zheng wrote:
>      def _add_to_queue(self, user, m, queue):
>          for x in [m] + list(m.get_patches()):
> -            Queue.objects.get_or_create(user=user, message=x, name=queue)
> +            q, created = Queue.objects.get_or_create(user=user, message=x, name=queue)
> +            if created:
> +                emit_event("MessageQueued", message=x, queue=q)

I'd "explode" queue into name and user here.  The idea is that we could
have something generic like this in mods/email.py:

diff --git a/mods/email.py b/mods/email.py
index 91c7d28..3ab1a73 100644
--- a/mods/email.py
+++ b/mods/email.py
@@ -74,6 +74,9 @@ Email information is configured in "INI" style:
                         BooleanSchema("reply_subject", "Set replying
subject",
                                       desc='Whether to set Subject to
"Re: xxx", if the event has an associated email message',
                                       default=True),
+                        BooleanSchema("to_user", "Send to user",
+                                      desc='Whether to set To to a user
email, if the event has an associated email message',
+                                      default=True),
                         StringSchema("to", "To", desc="Send email to"),
                         StringSchema("cc", "Cc", desc="Cc list"),
                         StringSchema("subject_template", "Subject
template",
@@ -246,6 +249,8 @@ Email information is configured in "INI" style:
                 headers["Reply-To"] = "<%s>" % mo.project.mailing_list
             if nt["reply_subject"] and mo:
                 subject = "Re: " + mo.subject if not
mo.subject.startswith("Re:") else mo.subject
+            if nt["to_user"] and 'user' in params:
+                to += params['user'].email
             if not (subject and body and (to or cc)):
                 continue
             headers["Subject"] = subject

... that would result in sending the message to the user that configured
a WatchQuery.

>  
>      def _drop_from_queue(self, user, m, queue):
>          query = Queue.objects.filter(user=user, message__in=m.get_patches() + [m],
>                                       name=queue)
> +        for q in query:
> +            emit_event("MessageDropping", message=q.message, queue=q)

Dropped?

>          q.delete()
>  
>      def _update_watch_queue(self, series):
> 

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH v2 09/12] maintainer: Add MessageQueued and MessageDropping events
Posted by Fam Zheng 5 years, 10 months ago
On Wed, 11/28 21:49, Paolo Bonzini wrote:
> Two small changes I'd like here:
> 
> On 28/11/18 15:35, Fam Zheng wrote:
> >      def _add_to_queue(self, user, m, queue):
> >          for x in [m] + list(m.get_patches()):
> > -            Queue.objects.get_or_create(user=user, message=x, name=queue)
> > +            q, created = Queue.objects.get_or_create(user=user, message=x, name=queue)
> > +            if created:
> > +                emit_event("MessageQueued", message=x, queue=q)
> 
> I'd "explode" queue into name and user here.  The idea is that we could
> have something generic like this in mods/email.py:
> 
> diff --git a/mods/email.py b/mods/email.py
> index 91c7d28..3ab1a73 100644
> --- a/mods/email.py
> +++ b/mods/email.py
> @@ -74,6 +74,9 @@ Email information is configured in "INI" style:
>                          BooleanSchema("reply_subject", "Set replying
> subject",
>                                        desc='Whether to set Subject to
> "Re: xxx", if the event has an associated email message',
>                                        default=True),
> +                        BooleanSchema("to_user", "Send to user",
> +                                      desc='Whether to set To to a user
> email, if the event has an associated email message',
> +                                      default=True),
>                          StringSchema("to", "To", desc="Send email to"),
>                          StringSchema("cc", "Cc", desc="Cc list"),
>                          StringSchema("subject_template", "Subject
> template",
> @@ -246,6 +249,8 @@ Email information is configured in "INI" style:
>                  headers["Reply-To"] = "<%s>" % mo.project.mailing_list
>              if nt["reply_subject"] and mo:
>                  subject = "Re: " + mo.subject if not
> mo.subject.startswith("Re:") else mo.subject
> +            if nt["to_user"] and 'user' in params:
> +                to += params['user'].email
>              if not (subject and body and (to or cc)):
>                  continue
>              headers["Subject"] = subject
> 
> ... that would result in sending the message to the user that configured
> a WatchQuery.

Sounds good, will change.

> 
> >  
> >      def _drop_from_queue(self, user, m, queue):
> >          query = Queue.objects.filter(user=user, message__in=m.get_patches() + [m],
> >                                       name=queue)
> > +        for q in query:
> > +            emit_event("MessageDropping", message=q.message, queue=q)
> 
> Dropped?

This event is before the q.delete() call, so dropping is more precise. What do you think?

> 
> >          q.delete()
> >  
> >      def _update_watch_queue(self, series):
> > 
> 

Fam

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel