Beispiel #1
0
def app(request):
    """ The demonstration counter application """
    s = get_invocations()
    min_sec = get_configuration(MIN_SEC).value
    max_sec = get_configuration(MAX_SEC).value
    poll = get_poll(service_name)
    return render(request, template+'app.html', {'stats': s, 'min': min_sec,
                  'max': max_sec, 'running': poll_running(poll)})
Beispiel #2
0
def app(request):
    """ The demonstration counter application """
    s = get_invocations()
    min_sec = get_configuration(MIN_SEC).value
    max_sec = get_configuration(MAX_SEC).value
    poll = get_poll(service_name)
    return render(request, template + 'app.html', {
        'stats': s,
        'min': min_sec,
        'max': max_sec,
        'running': poll_running(poll)
    })
Beispiel #3
0
def do_start():
    """ Start polling the service

        Returns JOSN {"running": true}
    """
    increment_counter(get_invocations())
    conf = get_configuration(SERVICE_URL)
    return create_running_response(start_poll(service_name, conf.value))
Beispiel #4
0
def do_start():
    """ Start polling the service

        Returns JOSN {"running": true}
    """
    increment_counter(get_invocations())
    conf = get_configuration(SERVICE_URL)
    return create_running_response(start_poll(service_name, conf.value))
Beispiel #5
0
def call_service(name):
    """ A Celery worker task (see http://www.celeryproject.org/) to perform a
        scheduled poll to the reference service.
    """
    log.info('Worker task called')
    try:
        next_id = None
        poll = get_poll(name)
        log.info('Expected {0}, current {1}'.format(poll.current_task_id,
                                                    call_service.request.id))
        if poll.current_task_id == call_service.request.id:
            log.info('Calling service at url {0}'.format(poll.url))
            try:
                r = requests.put(poll.url)

                if r.status_code is OK:
                    log.info('Good response from service')
                else:
                    log.error('Unable to call counter '
                              'service: {0}'.format(r.reason))
            except RequestException as e:
                log.error('Unable to call counter service: {0}'.format(e))

            min_sec = num(get_configuration(MIN_SEC).value)
            max_sec = num(get_configuration(MAX_SEC).value)
            if min_sec <= 0 or max_sec < min_sec:
                log.warning('Invalid min and max values set ({0}:{1}), using '
                            'defaults'.format(min_sec, max_sec))
                min_sec = num(MIN_SEC_DEFAULT)
                max_sec = num(MAX_SEC_DEFAULT)

            interval = random.randint(min_sec, max_sec)
            log.info('Continue running and schedule next poll for {0} seconds '
                     '({1}:{2})'.format(interval, min_sec, max_sec))
            next_id = call_service.apply_async(args=[name], countdown=interval)
            update_task_id(name, next_id)
        else:
            log.info('Stopping task (saved task is not this task)')
            remove_poll(name)
    except Exception as e:
        log.error('An error occured. Stopping poll: {0}'.format(e))
        remove_poll(name)
Beispiel #6
0
def call_service(name):
    """ A Celery worker task (see http://www.celeryproject.org/) to perform a
        scheduled poll to the reference service.
    """
    log.info('Worker task called')
    try:
        next_id = None
        poll = get_poll(name)
        log.info('Expected {0}, current {1}'.format(poll.current_task_id,
                 call_service.request.id))
        if poll.current_task_id == call_service.request.id:
            log.info('Calling service at url {0}'.format(poll.url))
            try:
                r = requests.put(poll.url)

                if r.status_code is OK:
                    log.info('Good response from service')
                else:
                    log.error('Unable to call counter '
                              'service: {0}'.format(r.reason))
            except RequestException as e:
                log.error('Unable to call counter service: {0}'.format(e))

            min_sec = num(get_configuration(MIN_SEC).value)
            max_sec = num(get_configuration(MAX_SEC).value)
            if min_sec <= 0 or max_sec < min_sec:
                log.warning('Invalid min and max values set ({0}:{1}), using '
                            'defaults'.format(min_sec, max_sec))
                min_sec = num(MIN_SEC_DEFAULT)
                max_sec = num(MAX_SEC_DEFAULT)

            interval = random.randint(min_sec, max_sec)
            log.info('Continue running and schedule next poll for {0} seconds '
                     '({1}:{2})'.format(interval, min_sec, max_sec))
            next_id = call_service.apply_async(args=[name], countdown=interval)
            update_task_id(name, next_id)
        else:
            log.info('Stopping task (saved task is not this task)')
            remove_poll(name)
    except Exception as e:
        log.error('An error occured. Stopping poll: {0}'.format(e))
        remove_poll(name)
Beispiel #7
0
def doc(request):
    """ Return a HTML representation of the current documentation """
    return HttpResponseRedirect(get_configuration(DOC_URL).value)
Beispiel #8
0
def source(request):
    """ Return a HTML representation of the current source """
    return HttpResponseRedirect(get_configuration(SOURCE_URL).value)
Beispiel #9
0
def release_notes(request):
    """ Return a HTML representation of the current releasenotes """
    return HttpResponseRedirect(get_configuration(RELEASE_NOTES_URL).value)
Beispiel #10
0
def provenance(request):
    """ Return a HTML representation of the current releasenotes """
    return HttpResponseRedirect(get_configuration(PROVENANCE_URL).value)
Beispiel #11
0
def factsheet(request):
    """ Return a HTML representation of the factsheet """
    return HttpResponseRedirect(get_configuration(FACTSHEET_URL).value)
Beispiel #12
0
def source(request):
    """ Return a HTML representation of the current source """
    return HttpResponseRedirect(get_configuration(SOURCE_URL).value)
Beispiel #13
0
def licence(request):
    """ Return a HTML representation of the current releasenotes """
    return HttpResponseRedirect(get_configuration(LICENCE_URL).value)
Beispiel #14
0
def release_notes(request):
    """ Return a HTML representation of the current releasenotes """
    return HttpResponseRedirect(get_configuration(RELEASE_NOTES_URL).value)
Beispiel #15
0
def doc(request):
    """ Return a HTML representation of the current documentation """
    return HttpResponseRedirect(get_configuration(DOC_URL).value)
Beispiel #16
0
def licence(request):
    """ Return a HTML representation of the current releasenotes """
    return HttpResponseRedirect(get_configuration(LICENCE_URL).value)
Beispiel #17
0
def provenance(request):
    """ Return a HTML representation of the current releasenotes """
    return HttpResponseRedirect(get_configuration(PROVENANCE_URL).value)
Beispiel #18
0
def factsheet(request):
    """ Return a HTML representation of the factsheet """
    return HttpResponseRedirect(get_configuration(FACTSHEET_URL).value)