Exemple #1
0
def test_logging_with_context(storage):
    import logging
    from jobcontrol.core import JobExecutionContext, JobControl
    from jobcontrol.config import JobControlConfig

    logger = logging.getLogger('foo_logger')

    build_id = storage.create_build('foo')
    jc = JobControl(storage=storage, config=JobControlConfig())

    jc._install_log_handler()

    logger.debug('This will be ignored')
    logger.info('This will be ignored')
    logger.error('This will be ignored')

    with JobExecutionContext(app=jc, job_id='foo', build_id=build_id):
        logger.debug('This is a log message [D]')
        logger.info('This is a log message [I]')
        logger.warning('This is a log message [W]')
        logger.error('This is a log message [E]')
        try:
            raise ValueError('foobar')
        except:
            logger.exception('Shit happens')

    logger.info('This will get ignored as well')

    # ------------------------------------------------------------

    assert len(list(storage.iter_log_messages(build_id))) == 5
Exemple #2
0
    def from_config(cls, config):
        """
        Initialize JobControl from some configuration.

        :param config:
            Either a :py:class:`jobcontrol.config.JobControlConfig`
            instance, or a dict to be passed as argument to that
            class constructor.

        :return:
            a :py:class:`JobControl` instance
        """

        if not isinstance(config, JobControlConfig):
            config = JobControlConfig(config)
        obj = cls(storage=config.get_storage(), config=config)
        return obj
def test_build_progress_reporting(storage):
    jc = JobControl(storage=storage, config=JobControlConfig())

    jc = JobControl(storage=storage,
                    config={
                        'jobs': [{
                            'id': 'foo_job',
                            'function':
                            'jobcontrol.utils.testing:job_with_progress',
                            'kwargs': {
                                'config': [(None, 5), (('foo', 'spam'), 2),
                                           (('foo', 'eggs'), 4),
                                           (('bar', 'bacon', 'X'), 8),
                                           (('bar', 'bacon', 'Y'), 16)]
                            }
                        }]
                    })

    build = jc.create_build(job_id='foo_job')
Exemple #4
0
    def __init__(self, storage, config):
        self.storage = storage

        if not isinstance(config, JobControlConfig):
            config = JobControlConfig(config)
        self.config = config