Exemplo n.º 1
0
class BaseWorker(Task):

    def process(self, data):
        raise NotImplementedError

    def run(self, *args, **kwargs):
        self.log = log
        self.session = DBSession()
        self.smtp = SmtpCache()
        self.log.debug('using session %r, %r' %
                       (self.session, id(self.session)))

        req = kwargs.get('data')
        self.log.info('[Task %s]: RECEIVED %r' % (self.name, req))

        self.process(req)

        return True

    def send_mail(self, sender, target, request, content):
        """ Send a mail """
        subject = 'Request %s' % request.status
        self.smtp.send_mail(sender, target, subject, content)

    def get_admin_mail(self, admin):
        """ Return admin email from ldap dict or model """
        if isinstance(admin, dict):
            return admin['email']
        else:
            return admin.email
Exemplo n.º 2
0
def configure_workers(sender=None, conf=None, **kwargs):
    # The Worker (child process of the celeryd) must have
    # it's own SQL Connection (A unix forking operation preserve fd)
    with open(sys.argv[1]) as fdesc:
        conf = yaml.load(fdesc, YAMLLoader)
    # XXX Register the database
    create_engine('pyvac', conf.get('databases').get('pyvac'), scoped=True)
    if conf.get('ldap'):
        LdapCache.configure(conf.get('ldap').get('conf'))
    SmtpCache.configure(conf.get('smtp'))

    # initialize configuration singleton
    ConfCache.configure(conf)
Exemplo n.º 3
0
    def run(self, *args, **kwargs):
        self.log = log
        self.session = DBSession()
        self.smtp = SmtpCache()
        self.log.debug('using session %r, %r' %
                       (self.session, id(self.session)))

        req = kwargs.get('data')
        # don't log credentials like in caldav.url
        params = req.copy()
        params.pop('caldav.url', None)
        self.log.info('[Task %s]: RECEIVED %r' % (self.name, params))

        self.process(req)

        return True
Exemplo n.º 4
0
    def run(self, *args, **kwargs):
        self.log = log
        self.session = DBSession()
        self.smtp = SmtpCache()
        self.log.info('using session %r, %r' % (self.session, id(self.session)))

        req = kwargs.get('data')
        self.log.info('RECEIVED %r' % req)

        self.process(req)

        return True
Exemplo n.º 5
0
class BaseWorker(Task):

    def process(self, data):
        raise NotImplementedError

    def run(self, *args, **kwargs):
        self.log = log
        self.session = DBSession()
        self.smtp = SmtpCache()
        self.log.debug('using session %r, %r' %
                       (self.session, id(self.session)))

        req = kwargs.get('data')
        # don't log credentials like in caldav.url
        params = req.copy()
        params.pop('caldav.url', None)
        self.log.info('[Task %s]: RECEIVED %r' % (self.name, params))

        self.process(req)

        return True

    def send_mail(self, sender, target, request, content):
        """ Send a mail """
        subject = 'Request %s (%s)' % (request.status, request.user.name)
        self.smtp.send_mail(sender, target, subject, content)

    def send_mail_ics(self, sender, target, request, content):
        """ Send a multipart mail with ics file as attachment """
        subject = 'Request %s (%s)' % (request.status, request.user.name)
        ics_content = request.generate_vcal_entry()
        self.smtp.send_mail_multipart(sender, target, subject, content,
                                      newpart=ics_content)

    def send_mail_custom(self, subject, sender, target, content):
        """ Send a mail """
        self.smtp.send_mail(sender, target, subject, content)

    def get_admin_mail(self, admin):
        """ Return admin email from ldap dict or model """
        if isinstance(admin, dict):
            return admin['email']
        else:
            return admin.email