

@pypi_packages.route('/sync')
def sync():
    "Sync local database with data from PyPI's API through a Celery task."
    if redis.exists(POLL_SIMPLE_THROTTLE):
        flash.warning('Already sycned once within the past hour. Not syncing until lock expires.')
        return redirect(url_for('.index'))
    task = update_package_list.delay()
    for _ in range(int((WAIT_UP_TO / SLEEP_FOR))):
        time.sleep(SLEEP_FOR)
        if (not task.ready()):
            continue
        results = task.get(propagate=False)
        if isinstance(results, Exception):
            if (str(results) == 'Failed to acquire lock.'):
                flash.info('Task scheduled, any new packages will appear within 1 minute.')
                return redirect(url_for('.index'))
            raise results
        if (not results):
            flash.info('No new packages found.')
            return redirect(url_for('.index'))
        if (len(results) < 5):
            flash.info('New packages: {}'.format(', '.join(results)))
        else:
            flash.modal('New packages found:\n{}'.format(', '.join(results)))
        return redirect(url_for('.index'))
    flash.info('Task scheduled, any new packages will appear within 15 minutes.')
    return redirect(url_for('.index'))

dataset/ETHPy150Open Robpol86/Flask-Large-Application-Example/pypi_portal/views/pypi/packages.py sync/original