示例#1
0
def _send_mail(user_ids, action_type, datarequest, job_title):
    for user_id in user_ids:
        try:
            user_data = model.User.get(user_id)
            extra_vars = {
                'datarequest': datarequest,
                'user': user_data,
                'site_title': config.get('ckan.site_title'),
                'site_url': config.get('ckan.site_url')
            }
            subject = base.render_jinja2(
                'emails/subjects/{0}.txt'.format(action_type), extra_vars)
            body = base.render_jinja2(
                'emails/bodies/{0}.txt'.format(action_type), extra_vars)
            tk.enqueue_job(mailer.mail_user, [user_data, subject, body],
                           title=job_title)
        except Exception:
            logging.exception(
                "Error sending notification to {0}".format(user_id))
示例#2
0
def enqueue_validation_job(package_id, resource_id):
    enqueue_args = {
        'fn': run_validation_job,
        'title': "run_validation_job: package_id: {} resource: {}".format(package_id, resource_id),
        'kwargs': {'resource': resource_id},
    }
    if t.check_ckan_version('2.8'):
        ttl = 24 * 60 * 60  # 24 hour ttl.
        rq_kwargs = {
            'ttl': ttl
        }
        if t.check_ckan_version('2.9'):
            rq_kwargs['failure_ttl'] = ttl
        enqueue_args['rq_kwargs'] = rq_kwargs
    # Optional variable, if not set, default queue is used
    queue = t.config.get('ckanext.validation.queue', None)
    if queue:
        enqueue_args['queue'] = queue
    t.enqueue_job(**enqueue_args)
示例#3
0
def send_email_dataset_notification(datasets_by_contacts, action_type):
    for contact in datasets_by_contacts:
        try:
            log.info("Preparing email data for {0} notification to {1}".format(
                action_type, contact.get('email')))
            datasets = []
            for contact_dataset in contact.get('datasets', {}):
                date = datetime.strptime(
                    contact_dataset.get('next_update_due'), '%Y-%m-%d')

                datasets.append({
                    'url':
                    h.url_for('dataset_read',
                              id=contact_dataset.get('name'),
                              _external=True),
                    'next_due_date':
                    date.strftime('%d/%m/%Y')
                })

            extra_vars = {'datasets': datasets}
            subject = render_jinja2(
                'emails/subjects/{0}.txt'.format(action_type), extra_vars)
            body = render_jinja2('emails/bodies/{0}.txt'.format(action_type),
                                 extra_vars)

            site_title = 'Data | Queensland Government'
            site_url = config.get('ckan.site_url')
            enqueue_job(mailer._mail_recipient, [
                contact.get('email'),
                contact.get('email'), site_title, site_url, subject, body
            ],
                        title=action_type)
            log.info(
                "Added email to job worker default queue for {0} notification to {1}"
                .format(action_type, contact.get('email')))
        except Exception as e:
            log.error("Error sending {0} notification to {1}".format(
                action_type, contact.get('email')))
            log.error(str(e))
示例#4
0
def enqueue_job(*args, **kwargs):
    try:
        return t.enqueue_job(*args, **kwargs)
    except AttributeError:
        from ckanext.rq.jobs import enqueue as enqueue_job_legacy
        return enqueue_job_legacy(*args, **kwargs)