Example #1
0
    def run(self):
        site_code = self._cfg.site_code
        period = int(self._cfg.status_monitoring_period)
        auth = (self._cfg.login, self._cfg.password)

        query = self._cfg.job_status_url

        self._log.info('started (site_code=%s period=%d secs)', site_code, period)

        last_check = 0

        while True:
            now = time.time()
            if now - last_check >= period:
                queue = PendingJobsQueue()
                for job_id in queue.items():
                    if self._debug:
                        self._log.debug('requesting status of site/job %s/%s', self._cfg.site_code, job_id)

                    resp = requests.get(url=query % (site_code, job_id), auth=auth)

                    if resp.ok:
                        if self._debug:
                            self._log.debug('got reply : %s', resp.text)

                        reply = json.loads(resp.text)

                        completion_code = reply['code']

                        if completion_code == 0:    # completed
                            # log it and remove the job from the queue
                            log.info('job %s completed ok', job_id)
                            queue.remove(job_id)
                        elif completion_code < 0:
                            # solid error => log it and remove the job from the queue
                            try:
                                code_msg = reply['status']
                            except KeyError:
                                code_msg = "unknown code"
                            log.error('job %s failed with code %d (%s)', job_id, completion_code, code_msg)
                            queue.remove(job_id)

                        # otherwise the job is still pending. Just leave it a is

                    else:
                        log.error("server replied with : %d - %s", resp.status_code, resp.reason)

                last_check = now

            if self._terminated:
                self._log.info('terminate request detected')
                break

            time.sleep(self.TERMINATE_CHECK_PERIOD)

        self._log.info('worker thread terminated')
Example #2
0
if __name__ == '__main__':
    gs = pycstbox.config.GlobalSettings()

    pycstbox.log.setup_logging()
    log = pycstbox.log.getLogger(name=SCRIPT_NAME)

    # process CLI args
    parser = pycstbox.cli.get_argument_parser(
        description=__doc__
    )
    args = parser.parse_args()

    pycstbox.log.set_loglevel_from_args(log, args)

    log.info('loading process configuration')
    process_cfg = ProcessConfiguration()

    # Loads the configuration parameters
    try:
        process_cfg.load(pycstbox.config.make_config_file_path(CONFIG_FILE_NAME))

    except ConfigParser.Error as e:
        log.fatal('configuration error (%s)', e)
        sys.exit(1)

    else:
        log.info('initializing export process')
        process = DWHVariableDefinitionsExportProcess()
        process.log_setLevel_from_args(args)
Example #3
0
pycstbox.cfgbroker for detailed documentation.
"""

import sys

import pycstbox.cfgbroker as cfgbroker
import pycstbox.log as log
import pycstbox.cli as cli
import pycstbox.dbuslib as dbuslib

if __name__ == '__main__':
    log.setup_logging('cfgbroker.main')

    parser = cli.get_argument_parser('CSTBox Configuration Broker service')
    args = parser.parse_args()

    try:
        log.info('starting')
        dbuslib.dbus_init()

        svc = cfgbroker.ConfigurationBroker(dbuslib.get_bus())
        svc.log_setLevel(log.loglevel_from_args(args))
        svc.start()

    except Exception as e:  #pylint: disable=W0703
        log.exception(e)
        sys.exit(e)

    else:
        log.info('terminated')
Example #4
0
pycstbox.cfgbroker for detailed documentation.
"""

import sys

import pycstbox.cfgbroker as cfgbroker
import pycstbox.log as log
import pycstbox.cli as cli
import pycstbox.dbuslib as dbuslib

if __name__ == '__main__':
    log.setup_logging('cfgbroker.main')

    parser = cli.get_argument_parser('CSTBox Configuration Broker service')
    args = parser.parse_args()

    try:
        log.info('starting')
        dbuslib.dbus_init()

        svc = cfgbroker.ConfigurationBroker(dbuslib.get_bus())
        svc.log_setLevel(log.loglevel_from_args(args))
        svc.start()

    except Exception as e:  #pylint: disable=W0703
        log.exception(e)
        sys.exit(e)

    else:
        log.info('terminated')