Esempio n. 1
0
def _run_status(conf, starttime):
    """
    define the run status evaulating the conditional expression.
    """

    if 'run' not in conf:
        logging.error('No run key in conf')
        return conf

    run = conf['run']

    if not isinstance(run, basestring):
        return conf

    run_re = re.compile(r'(since|until|for):(\S+)')

    matched = run_re.match(run).groups()

    if matched[0] == 'since':
        run = datetime.now() > datetime.strptime(matched[1],
                                                 '%Y-%m-%d:%H:%M:%S')
    elif matched[0] == 'until':
        run = datetime.now() < datetime.strptime(matched[1],
                                                 '%Y-%m-%d:%H:%M:%S')
    elif matched[0] == 'for':
        run = (datetime.now() - starttime) < timedelta(seconds=int(matched[1]))

    conf['run'] = run

    return conf
Esempio n. 2
0
    def worker_wrapper(*args, **kwargs):
        """
        Wrapper of the worker.
        manages exceptions and logs.
        """
        if 'rds' in kwargs:
            label = 'block_sync=%(pnn)s:%(rds)s'
            level = logging.VNOTICE
        else:
            label = 'pnn_sync=%(pnn)s'
            level = logging.SUMMARY

        logging.my_fmt(label=label % kwargs)

        logging.log(level, 'Starting Task')

        try:
            ret = func(*args, **kwargs)

        #pylint: disable=broad-except
        except Exception as exc:
            logging.error('Exception %s raised: %s',
                          type(exc).__name__,
                          traceback.format_exc().replace('\n', '~~'))
            return None

        timing = ret.pop('timing')
        if 'return' in ret:
            ret = ret['return']

        logging.log(level, 'Finished: %s; timing: %s', ret, timing)

        return ret
Esempio n. 3
0
def dataset_replica_update(dataset, pnn, rse, pcli, account, dry):
    """
    Just wrapping the update method.
    """

    try:
        rcli = Client(account=account)
    except CannotAuthenticate:
        logging.warning("cannot authenticate with account %s, skipping pnn %s",
                        account, pnn)
        return None

    logging.my_fmt(label='update:rse=%s:rds=%s' % (pnn, dataset))

    logging.notice('Starting.')

    try:
        ret = _replica_update(dataset, pnn, rse, pcli, rcli, dry)

    #pylint: disable=broad-except
    except Exception as exc:
        logging.error('Exception %s raised: %s',
                      type(exc).__name__,
                      traceback.format_exc().replace('\n', '~~'))
        return None

    logging.notice('Finished %s.', ret)