コード例 #1
0
def sigterm_handler(signum, frame):
    '''Intercept sigterm and terminate all processes.
    '''
    if captureproc and captureproc.poll() is None:
        captureproc.terminate()
    terminate(True)
    sys.exit(0)
コード例 #2
0
ファイル: capture.py プロジェクト: lkiesow/pyCA
def sigterm_handler(signum, frame):
    '''Intercept sigterm and terminate all processes.
    '''
    if captureproc and captureproc.poll() is None:
        captureproc.terminate()
    terminate(True)
    sys.exit(0)
コード例 #3
0
def control_loop():
    '''Main loop, retrieving the schedule.
    '''
    set_service_status_immediate(Service.SCHEDULE, ServiceStatus.BUSY)
    notify.notify('READY=1')
    while not terminate():
        notify.notify('WATCHDOG=1')
        # Try getting an updated schedule
        get_schedule()
        session = get_session()
        next_event = session.query(UpcomingEvent)\
                            .filter(UpcomingEvent.end > timestamp())\
                            .order_by(UpcomingEvent.start)\
                            .first()
        if next_event:
            logger.info('Next scheduled recording: %s',
                        datetime.fromtimestamp(next_event.start))
            notify.notify('STATUS=Next scheduled recording: %s' %
                          datetime.fromtimestamp(next_event.start))
        else:
            logger.info('No scheduled recording')
            notify.notify('STATUS=No scheduled recording')
        session.close()

        next_update = timestamp() + config('agent', 'update_frequency')
        while not terminate() and timestamp() < next_update:
            time.sleep(0.1)

    logger.info('Shutting down schedule service')
    set_service_status_immediate(Service.SCHEDULE, ServiceStatus.STOPPED)
コード例 #4
0
ファイル: agentstate.py プロジェクト: wederw/pyCA
def control_loop():
    '''Main loop, updating the capture agent state.
    '''
    set_service_status(Service.AGENTSTATE, ServiceStatus.BUSY)
    while not terminate():
        update_agent_state()

        next_update = timestamp() + config()['agent']['update_frequency']
        while not terminate() and timestamp() < next_update:
            time.sleep(0.1)

    logger.info('Shutting down agentstate service')
    set_service_status(Service.AGENTSTATE, ServiceStatus.STOPPED)
コード例 #5
0
def control_loop():
    '''Main loop, updating the capture agent state.
    '''
    set_service_status(Service.AGENTSTATE, ServiceStatus.BUSY)
    notify.notify('READY=1')
    notify.notify('STATUS=Running')
    while not terminate():
        notify.notify('WATCHDOG=1')

        next_update = timestamp() + config('agent', 'update_frequency')
        while not terminate() and timestamp() < next_update:
            time.sleep(0.1)

        if not terminate():
            update_agent_state()

    logger.info('Shutting down agentstate service')
    set_service_status(Service.AGENTSTATE, ServiceStatus.STOPPED)
コード例 #6
0
ファイル: schedule.py プロジェクト: lkiesow/pyCA
def control_loop():
    '''Main loop, retrieving the schedule.
    '''
    set_service_status(Service.SCHEDULE, ServiceStatus.BUSY)
    while not terminate():
        # Try getting an updated schedule
        get_schedule()
        q = get_session().query(UpcomingEvent)\
                         .filter(UpcomingEvent.end > timestamp())
        if q.count():
            logger.info('Next scheduled recording: %s',
                        datetime.fromtimestamp(q[0].start))
        else:
            logger.info('No scheduled recording')

        next_update = timestamp() + config()['agent']['update_frequency']
        while not terminate() and timestamp() < next_update:
            time.sleep(0.1)

    logger.info('Shutting down schedule service')
    set_service_status(Service.SCHEDULE, ServiceStatus.STOPPED)
コード例 #7
0
def control_loop():
    '''Main loop, retrieving the schedule.
    '''
    set_service_status(Service.SCHEDULE, ServiceStatus.BUSY)
    while not terminate():
        # Try getting an updated schedule
        get_schedule()
        q = get_session().query(UpcomingEvent)\
                         .filter(UpcomingEvent.end > timestamp())
        if q.count():
            logger.info('Next scheduled recording: %s',
                        datetime.fromtimestamp(q[0].start))
        else:
            logger.info('No scheduled recording')

        next_update = timestamp() + config()['agent']['update_frequency']
        while not terminate() and timestamp() < next_update:
            time.sleep(0.1)

    logger.info('Shutting down schedule service')
    set_service_status(Service.SCHEDULE, ServiceStatus.STOPPED)
コード例 #8
0
ファイル: ingest.py プロジェクト: lkiesow/pyCA
def control_loop():
    '''Main loop of the capture agent, retrieving and checking the schedule as
    well as starting the capture process if necessry.
    '''
    set_service_status(Service.INGEST, ServiceStatus.IDLE)
    while not terminate():
        # Get next recording
        events = get_session().query(RecordedEvent)\
                              .filter(RecordedEvent.status ==
                                      Status.FINISHED_RECORDING)
        if events.count():
            safe_start_ingest(events[0])
        time.sleep(1.0)
    logger.info('Shutting down ingest service')
    set_service_status(Service.INGEST, ServiceStatus.STOPPED)
コード例 #9
0
ファイル: ingest.py プロジェクト: wederw/pyCA
def control_loop():
    '''Main loop of the capture agent, retrieving and checking the schedule as
    well as starting the capture process if necessry.
    '''
    set_service_status(Service.INGEST, ServiceStatus.IDLE)
    while not terminate():
        # Get next recording
        event = get_session().query(RecordedEvent)\
                             .filter(RecordedEvent.status ==
                                     Status.FINISHED_RECORDING).first()
        if event:
            safe_start_ingest(event)
        time.sleep(1.0)
    logger.info('Shutting down ingest service')
    set_service_status(Service.INGEST, ServiceStatus.STOPPED)
コード例 #10
0
ファイル: capture.py プロジェクト: lkiesow/pyCA
def control_loop():
    '''Main loop of the capture agent, retrieving and checking the schedule as
    well as starting the capture process if necessry.
    '''
    set_service_status(Service.CAPTURE, ServiceStatus.IDLE)
    while not terminate():
        # Get next recording
        event = get_session().query(UpcomingEvent)\
                             .filter(UpcomingEvent.start <= timestamp())\
                             .filter(UpcomingEvent.end > timestamp())\
                             .first()
        if event:
            safe_start_capture(event)
        time.sleep(1.0)
    logger.info('Shutting down capture service')
    set_service_status(Service.CAPTURE, ServiceStatus.STOPPED)
コード例 #11
0
def control_loop():
    '''Main loop of the capture agent, retrieving and checking the schedule as
    well as starting the capture process if necessry.
    '''
    set_service_status(Service.CAPTURE, ServiceStatus.IDLE)
    while not terminate():
        # Get next recording
        event = get_session().query(UpcomingEvent)\
                             .filter(UpcomingEvent.start <= timestamp())\
                             .filter(UpcomingEvent.end > timestamp())\
                             .first()
        if event:
            safe_start_capture(event)
        time.sleep(1.0)
    logger.info('Shutting down capture service')
    set_service_status(Service.CAPTURE, ServiceStatus.STOPPED)
コード例 #12
0
def control_loop():
    '''Main loop of the capture agent, retrieving and checking the schedule as
    well as starting the capture process if necessry.
    '''
    set_service_status_immediate(Service.CAPTURE, ServiceStatus.IDLE)
    notify.notify('READY=1')
    notify.notify('STATUS=Waiting')
    while not terminate():
        notify.notify('WATCHDOG=1')
        # Get next recording
        session = get_session()
        event = session.query(UpcomingEvent)\
                       .filter(UpcomingEvent.start <= timestamp())\
                       .filter(UpcomingEvent.end > timestamp())\
                       .first()
        if event:
            safe_start_capture(event)
        session.close()
        time.sleep(1.0)
    logger.info('Shutting down capture service')
    set_service_status(Service.CAPTURE, ServiceStatus.STOPPED)
コード例 #13
0
def control_loop():
    '''Main loop of the capture agent, retrieving and checking the schedule as
    well as starting the capture process if necessry.
    '''
    set_service_status_immediate(Service.INGEST, ServiceStatus.IDLE)
    notify.notify('READY=1')
    notify.notify('STATUS=Running')
    while not terminate():
        notify.notify('WATCHDOG=1')
        # Get next recording
        session = get_session()
        event = session.query(RecordedEvent)\
                       .filter(RecordedEvent.status ==
                               Status.FINISHED_RECORDING).first()
        if event:
            delay = random.randint(config('ingest', 'delay_min'),
                                   config('ingest', 'delay_max'))
            logger.info("Delaying ingest for %s seconds", delay)
            time.sleep(delay)
            safe_start_ingest(event)
        session.close()
        time.sleep(1.0)
    logger.info('Shutting down ingest service')
    set_service_status(Service.INGEST, ServiceStatus.STOPPED)
コード例 #14
0
ファイル: __main__.py プロジェクト: lkiesow/pyCA
def sigint_handler(signum, frame):
    '''Intercept sigint and terminate services gracefully.
    '''
    utils.terminate(True)
コード例 #15
0
ファイル: test_main.py プロジェクト: lkiesow/pyCA
 def test_sigterm(self):
     try:
         __main__.sigterm_handler(0, 0)
     except BaseException as e:
         assert e.code == 0
         assert utils.terminate()
コード例 #16
0
def sigint_handler(signum, frame):
    '''Intercept sigint and terminate services gracefully.
    '''
    utils.terminate(True)
コード例 #17
0
ファイル: test_capture.py プロジェクト: opencast/pyCA
 def test_sigterm(self):
     with self.assertRaises(BaseException) as e:
         capture.sigterm_handler(0, 0)
     self.assertEqual(e.exception.code, 0)
     self.assertTrue(utils.terminate())
コード例 #18
0
ファイル: test_utils.py プロジェクト: wederw/pyCA
 def test_configure_service(self):
     utils.terminate(False)
     utils.get_service = lambda x: 'x'
     utils.configure_service('x')
     assert config.config()['service-x'] == 'x'
コード例 #19
0
 def test_sigterm(self):
     try:
         capture.sigterm_handler(0, 0)
     except BaseException as e:
         assert e.code == 0
         assert utils.terminate()
コード例 #20
0
 def test_service(self):
     utils.terminate(False)
     utils.get_service = lambda x: 'x'
     self.assertEqual(utils.service('x'), 'x')