<commit_before>import sys
import logging
from teuthology.sentry import get_client as get_sentry_client
from .config import config as teuth_config

log = logging.getLogger(__name__)


def run_one_task(taskname, **kwargs):
    submod = taskname
    subtask = 'task'
    if '.' in taskname:
        (submod, subtask) = taskname.rsplit('.', 1)
    parent = __import__('teuthology.task', globals(), locals(), [submod], 0)
    mod = getattr(parent, submod)
    fn = getattr(mod, subtask)
    return fn(**kwargs)


def run_tasks(tasks, ctx):
    stack = []
    try:
        for taskdict in tasks:
            try:
                ((taskname, config),) = taskdict.iteritems()
            except ValueError:
                raise RuntimeError('Invalid task definition: %s' % taskdict)
            log.info('Running task %s...', taskname)
            manager = run_one_task(taskname, ctx=ctx, config=config)
            if hasattr(manager, '__enter__'):
                manager.__enter__()
                stack.append(manager)
    except Exception, e:
        ctx.summary['success'] = False
        if 'failure_reason' not in ctx.summary:
            ctx.summary['failure_reason'] = str(e)
        log.exception('Saw exception from tasks.')
        sentry = get_sentry_client()
        if sentry:
            exc_id = sentry.get_ident(sentry.captureException())
            event_url = "{server}/search?q={id}".format(
                server=teuth_config.sentry_server, id=exc_id)
            log.exception(" Sentry event: %s" % event_url)
            sentry_url_list = ctx.summary.get('sentry_events', [])
            sentry_url_list.append(event_url)
            ctx.summary['sentry_events'] = sentry_url_list
        if ctx.config.get('interactive-on-error'):
            from .task import interactive
            log.warning('Saw failure, going into interactive mode...')
            interactive.task(ctx=ctx, config=None)
    finally:
        try:
            exc_info = sys.exc_info()
            while stack:
                manager = stack.pop()
                log.debug('Unwinding manager %s', manager)
                try:
                    suppress = manager.__exit__(*exc_info)<commit_msg>Add tags! Task name and owner to start.<commit_after>import sys
import logging
from teuthology.sentry import get_client as get_sentry_client
from .config import config as teuth_config

log = logging.getLogger(__name__)


def run_one_task(taskname, **kwargs):
    submod = taskname
    subtask = 'task'
    if '.' in taskname:
        (submod, subtask) = taskname.rsplit('.', 1)
    parent = __import__('teuthology.task', globals(), locals(), [submod], 0)
    mod = getattr(parent, submod)
    fn = getattr(mod, subtask)
    return fn(**kwargs)


def run_tasks(tasks, ctx):
    stack = []
    try:
        for taskdict in tasks:
            try:
                ((taskname, config),) = taskdict.iteritems()
            except ValueError:
                raise RuntimeError('Invalid task definition: %s' % taskdict)
            log.info('Running task %s...', taskname)
            manager = run_one_task(taskname, ctx=ctx, config=config)
            if hasattr(manager, '__enter__'):
                manager.__enter__()
                stack.append(manager)
    except Exception, e:
        ctx.summary['success'] = False
        if 'failure_reason' not in ctx.summary:
            ctx.summary['failure_reason'] = str(e)
        log.exception('Saw exception from tasks.')
        sentry = get_sentry_client()
        if sentry:
            tags = {
                'task': taskname,
                'owner': ctx.owner,
            }
            exc_id = sentry.get_ident(sentry.captureException(tags=tags))
            event_url = "{server}/search?q={id}".format(
                server=teuth_config.sentry_server, id=exc_id)
            log.exception(" Sentry event: %s" % event_url)
            sentry_url_list = ctx.summary.get('sentry_events', [])
            sentry_url_list.append(event_url)
            ctx.summary['sentry_events'] = sentry_url_list
        if ctx.config.get('interactive-on-error'):
            from .task import interactive
            log.warning('Saw failure, going into interactive mode...')
            interactive.task(ctx=ctx, config=None)
    finally:
        try:
            exc_info = sys.exc_info()
            while stack:
                manager = stack.pop()
                log.debug('Unwinding manager %s', manager)
                try:
                    suppress = manager.__exit__(*exc_info)
{'fraction_non_alphanumeric': 0.11324503311258279, 'fraction_numerical': 0.0008830022075055188, 'mean_word_length': 2.1378116343490303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7186073', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1298, 'n_words': 301}