Beispiel #1
0
async def update_poll_task_urls(context,
                                callback,
                                min_seconds_left=300,
                                args=(),
                                kwargs=None):
    """Update the Azure urls to poll.

    Queue.pollTaskUrls() returns an ordered list of Azure url pairs to
    poll for task "hints".  This list is valid until expiration.

    This function checks for an up-to-date poll_task_urls; if non-existent
    or near expiration, get new poll_task_urls.

    http://docs.taskcluster.net/queue/worker-interaction/

    Args:
        context (scriptworker.context.Context): the scriptworker context.
        callback (function): This should be context.queue.pollTaskUrls outside
            of testing.
        min_seconds_left (int, optional):  We have an expiry datestring;
            if we have less than min_seconds_left seconds left, then update
            the urls.  Defaults to 300.
        args (list, optional): the args to pass to the callback.  Defaults to ()
        kwargs (dict, optional): the kwargs to pass to the callback.  Defaults to None.
    """
    urls = context.poll_task_urls
    if urls is not None:
        # check expiration
        expires = datestring_to_timestamp(urls['expires'])
        seconds_left = int(expires - time.time())
        if seconds_left >= min_seconds_left:
            return
    log.debug("Updating poll_task_urls...")
    kwargs = kwargs or {}
    context.poll_task_urls = await callback(*args, **kwargs)
Beispiel #2
0
async def update_poll_task_urls(context, callback, min_seconds_left=300, args=(), kwargs=None):
    """Queue.pollTaskUrls() returns an ordered list of Azure url pairs to
    poll for task "hints".  This list is valid until expiration.

    This function checks for an up-to-date poll_task_urls; if non-existent
    or near expiration, get new poll_task_urls.

    http://docs.taskcluster.net/queue/worker-interaction/
    """
    urls = context.poll_task_urls
    if urls is not None:
        # check expiration
        expires = datestring_to_timestamp(urls['expires'])
        seconds_left = int(expires - time.time())
        log.debug("poll_task_urls expires in %d seconds" % seconds_left)
        if seconds_left >= min_seconds_left:
            return
    log.debug("Updating poll_task_urls...")
    kwargs = kwargs or {}
    context.poll_task_urls = await callback(*args, **kwargs)
Beispiel #3
0
async def update_poll_task_urls(context,
                                callback,
                                min_seconds_left=300,
                                args=(),
                                kwargs=None):
    """Queue.pollTaskUrls() returns an ordered list of Azure url pairs to
    poll for task "hints".  This list is valid until expiration.

    This function checks for an up-to-date poll_task_urls; if non-existent
    or near expiration, get new poll_task_urls.

    http://docs.taskcluster.net/queue/worker-interaction/
    """
    urls = context.poll_task_urls
    if urls is not None:
        # check expiration
        expires = datestring_to_timestamp(urls['expires'])
        seconds_left = int(expires - time.time())
        log.debug("poll_task_urls expires in %d seconds" % seconds_left)
        if seconds_left >= min_seconds_left:
            return
    log.debug("Updating poll_task_urls...")
    kwargs = kwargs or {}
    context.poll_task_urls = await callback(*args, **kwargs)
Beispiel #4
0
def test_datestring_to_timestamp(datestring):
    assert utils.datestring_to_timestamp(datestring) == 1460778384
Beispiel #5
0
 def test_datestring_to_timestamp(self, datestring):
     assert utils.datestring_to_timestamp(datestring) == 1460778384