Example #1
0
 def abort(self, trans):
     if self.td.registered:
         self.session.expunge_all()
         # so content rules can match again
         cr_handlers.close(None)
     self.td.reset()
     self._clear_session()
Example #2
0
 def rollback(self):
     if self.dm.td.registered:
         self.dm.session.expunge_all()
         if len(self.old) > 0:
             for ob in self.old:
                 self.dm.session.add(ob)
         else:
             # allow content rules to run again
             cr_handlers.close(None)
Example #3
0
 def rollback(self):
     if self.dm.td.registered:
         self.dm.session.expunge_all()
         if len(self.old) > 0:
             for ob in self.old:
                 self.dm.session.add(ob)
         else:
             # allow content rules to run again
             cr_handlers.close(None)
Example #4
0
def _send_notification(context, job, missing_files, userid):
    args = dict(
        userid=userid,
        exp_time=job.meta.exp_time,
        filenames=tuple(map(_filename_from_path, job.meta.filepaths)),
        done_url=job.done_url,
        missing_files=missing_files,
    )
    ctx_wrapper = IContextWrapper(context)(**args)
    evt = DownloadReady(ctx_wrapper)
    notify(evt)
    # Make sure to close the event, otherwise subsequent
    # notifications will not trigger the content rule.
    # This is normally done automatically on IEndRequestEvent
    # but that doesn't seem to trigger on async jobs; and
    # would not work for multiple notify( triggers anyway.
    close(evt)
Example #5
0
def _send_notification(context, job, missing_files, userid):
    args = dict(
        userid=userid,
        exp_time=job.meta.exp_time,
        filenames=tuple(map(_filename_from_path, job.meta.filepaths)),
        done_url=job.done_url,
        missing_files=missing_files,
    )
    ctx_wrapper = IContextWrapper(context)(**args)
    evt = DownloadReady(ctx_wrapper)
    notify(evt)
    logger.info("Debug: Notify DownloadReady")
    # Make sure to close the event, otherwise subsequent
    # notifications will not trigger the content rule.
    # This is normally done automatically on IEndRequestEvent
    # but that doesn't seem to trigger on async jobs; and
    # would not work for multiple notify( triggers anyway.
    close(evt)
    def operations(message, site):
        def get_object(site, path):
            """ Return the object at given path
                or its first existing parent
            """
            obj = get_object_having_path(path)
            if obj is None:
                try:
                    path = "/".join(path.split("/")[:-1])
                    return get_object(site, path)
                except Exception:
                    return None
            else:
                if obj == site:
                    return None
                return obj
            return None

        msg = json.loads(message)
        """ This object is the object related to notification we want to send.
            Sometimes it is missing (example: on deleted items) so a parent
            will be used for that case.

            But the content_url is not changed, basically we just make sure
            the notification is sent.
        """
        obj = get_object(site, msg['path'])

        if obj is not None:
            catalog = get_catalog()
            users = catalog.search_users_by_preferences(
                tags=msg['tags'], events=[msg.get('events', '')], mode="or")
            for user_id in users:
                msg['user_id'] = user_id
                evt = SendEEANotificationEvent(obj, json.dumps(msg))
                notify(evt)
                close(evt)  # make sure it will work for multiple notify(
        else:
            LOGGER.error("Object with path {0} not found.".format(msg['path']))

        return True
Example #7
0
 def abort(self, trans):
     if self.td.registered:
         self.session.expunge_all()
         # so content rules can match again
         cr_handlers.close(None)
     self.td.reset()