Exemplo n.º 1
0
def reset():
    """
    Reset the Transiter database.

    This operation drops all of the Transiter tables in the database, if they
    exist, and then creates them. All existing data will be lost.
    """
    print("Deleting old tables...")
    dbconnection.delete_all_tables()
    print("Upgrading database...")
    dbconnection.upgrade_database()
    client.refresh_tasks()
    print("Done.")
Exemplo n.º 2
0
def _execute_system_update(system_update_pk):
    context = _mark_update_started(system_update_pk)

    # Pause all other activity on this system to avoid database concurrency problems
    # during the large upcoming unit of works.
    client.refresh_tasks()

    try:
        feed_ids_to_update, feed_ids_to_delete = _install_system_configuration(
            system_update_pk
        )
        for feed_id in feed_ids_to_update:
            feed_update, exception = updatemanager.execute_feed_update(
                feed_update_pk=updatemanager.create_feed_update(
                    context.system_id, feed_id
                )
            )
            if feed_update.status != models.FeedUpdate.Status.SUCCESS:
                if exception is None:
                    exception = exceptions.InstallError(
                        message=(
                            f"Failed to update feed (id={feed_id}); "
                            f"status: {feed_update.status}; "
                            f"result: {feed_update.result}"
                        )
                    )
                raise exceptions.InstallError(
                    message=(
                        f"Failed to update a feed (id={feed_id}) "
                        f"that is required for install"
                    )
                ) from exception
        for feed_id in feed_ids_to_delete:
            _delete_feed(context.system_id, feed_id)
        _mark_update_completed(
            context, models.SystemUpdate.Status.SUCCESS,
        )
    except Exception:
        _mark_update_completed(
            context, models.SystemUpdate.Status.FAILED, traceback.format_exc()
        )
        logger.debug("Install or update of system failed", exc_info=True)

    client.refresh_tasks()
Exemplo n.º 3
0
def scheduler_refresh_tasks():
    """
    Refresh scheduler tasks

    When this endpoint is hit the scheduler inspects the database and ensures that the right tasks are being scheduled
    and with the right periodicity, etc.
    This process happens automatically when an event occurs that
    potentially requires the tasks list to be changed, like a system install or delete.
    This endpoint is designed for the case when an admin manually edits something in the database and
    wants the scheduler to reflect that edit.
    """
    return client.refresh_tasks()
Exemplo n.º 4
0
def delete_by_id(system_id, error_if_not_exists=True, sync=True):
    """
    Delete a transit system
    """
    with dbconnection.inline_unit_of_work():
        system = systemqueries.get_by_id(system_id)
        if system is not None:
            system.status = models.System.SystemStatus.DELETING
            if not sync:
                system.id = system.id + "_deleting_" + str(uuid.uuid4())
                system_id = system.id
        elif error_if_not_exists:
            raise exceptions.IdNotFoundError
        else:
            return
    client.refresh_tasks()

    sync_to_function = {
        True: _complete_delete_operation,
        False: _complete_delete_operation_async.delay,
    }
    sync_to_function[sync](system_id)
Exemplo n.º 5
0
def test_refresh_tasks__do_not_swallow_all_exceptions(scheduler_post_response):
    scheduler_post_response.raise_for_status.side_effect = ValueError()

    with pytest.raises(ValueError):
        client.refresh_tasks()
Exemplo n.º 6
0
def test_refresh_tasks__fail(scheduler_post_response):
    scheduler_post_response.raise_for_status.side_effect = requests.RequestException()

    assert client.refresh_tasks() is False
Exemplo n.º 7
0
def test_refresh_tasks__pass(scheduler_post_response):
    scheduler_post_response.raise_for_status = lambda: None

    assert client.refresh_tasks() is True
Exemplo n.º 8
0
def set_auto_update_enabled(system_id, auto_update):
    with dbconnection.inline_unit_of_work():
        response = systemqueries.set_auto_update_enabled(system_id, auto_update)
    client.refresh_tasks()
    return response