Beispiel #1
0
import celery
from ptero_common import nicer_logging

LOG = nicer_logging.getLogger(__name__)


def execute_task(name, *args, **kwargs):
    LOG.debug('Execute task: %s, %s, %s', name, args, kwargs)
    task = celery.current_app.tasks[_full_task_name(name)]
    task.delay(*args, **kwargs)


_BASE_PATH = 'ptero_petri.implementation.celery_tasks.'
_REGISTERED_TASKS = {
    'NotifyTransition': _BASE_PATH + 'notify_transition.NotifyTransition',
    'NotifyPlace': _BASE_PATH + 'notify_place.NotifyPlace',
}


def _full_task_name(name):
    return _REGISTERED_TASKS[name]
from flask import g
import urllib
from ptero_common import nicer_logging
import os
from ptero_workflow.urls import url_for

LOG = nicer_logging.getLogger(__name__)
LIMIT = os.environ.get("PTERO_WORKFLOW_DEFAULT_STATUS_UPDATES_LIMIT", 500)


def report(workflow_id, since=None, limit=LIMIT):
    updates, timestamp, num_remaining = g.backend.get_limited_workflow_status_updates(
            workflow_id=workflow_id, since=since, limit=int(limit))

    base_url = url_for('report', report_type='limited-workflow-status-updates')

    url_query_string_args = {'workflow_id': workflow_id, 'limit':limit}

    if timestamp is not None:
        format_str = '%Y-%m-%d %H:%M:%S.%f'
        url_query_string_args['since'] = timestamp.strftime(format_str)
    else:
        url_query_string_args['since'] = since

    url = '%s?%s' % (base_url, urllib.urlencode(url_query_string_args))

    return {
            'updateUrl': url,
            'statusUpdates': updates,
            'numRemaining': num_remaining,
    }