magpie.cli.sync_resources¶
Synchronize local and remote resources.
To implement a new service, see magpie.cli.sync_services.SyncServiceInterface
.
See also
Attributes¶
Functions¶
Main function to sync resources with remote server. |
|
|
Merge resources_local and resources_remote, adding the following keys to the output: |
|
Sorts a nested resource dictionary. |
|
Make sure the RemoteResourcesSyncInfo entry exists in the database. |
|
Request remote resources, depending on service type. |
|
Delete all RemoteResource based on a Service.resource_id. |
|
Creates a main resource for a service, whether one currently exists or not. |
|
Writes remote resources to database. |
|
|
Reads remote resources from the RemoteResources table. No external request is made. |
|
|
Obtain the date-time of the last known sync event for a service. |
|
Get remote resources for all services of a certain type. |
|
Get remote resources for a single service. |
|
Main function to get all remote resources for each service and write to database. |
|
|
|
|
|
Main entry point for cron service. |
Module Contents¶
- magpie.cli.sync_resources.merge_local_and_remote_resources(resources_local: magpie.typedefs.RemoteResourceTree, service_sync_type: magpie.typedefs.Str, service_id: int, session: sqlalchemy.orm.session.Session) magpie.typedefs.RemoteResourceTree [source]¶
Main function to sync resources with remote server.
- magpie.cli.sync_resources._merge_resources(resources_local: magpie.typedefs.RemoteResourceTree, resources_remote: magpie.typedefs.RemoteResourceTree, max_depth: int | None = None) magpie.typedefs.RemoteResourceTree [source]¶
Merge resources_local and resources_remote, adding the following keys to the output:
remote_id: id of the RemoteResource
matches_remote: True or False depending if the resource is present on the remote server
- Returns:
Dictionary tree of the merged resources.
- magpie.cli.sync_resources._sort_resources(resources: magpie.typedefs.RemoteResourceTree) None [source]¶
Sorts a nested resource dictionary.
The dictionary is expected to be valid as per
sync_services.is_valid_resource_schema()
.- Returns:
None. Inplace modification.
- magpie.cli.sync_resources._ensure_sync_info_exists(service_resource_id: int, session: sqlalchemy.orm.session.Session) None [source]¶
Make sure the RemoteResourcesSyncInfo entry exists in the database.
- magpie.cli.sync_resources._get_remote_resources(service: magpie.models.Service) magpie.typedefs.JSON [source]¶
Request remote resources, depending on service type.
- Parameters:
service – service for which to fetch remove children resources
- Returns:
nested content as
{"node_name": {"children": JSON, "resource_type": "resource_type"}}
- magpie.cli.sync_resources._delete_records(service_id, session)[source]¶
Delete all RemoteResource based on a Service.resource_id.
- magpie.cli.sync_resources._create_main_resource(service_id: int, session: sqlalchemy.orm.session.Session) None [source]¶
Creates a main resource for a service, whether one currently exists or not.
Each RemoteResourcesSyncInfo has a main RemoteResource of the same name as the service. This is similar to the Service and Resource relationship.
- magpie.cli.sync_resources._update_db(remote_resources: magpie.typedefs.RemoteResourceTree, service_id: int, session: sqlalchemy.orm.session.Session) None [source]¶
Writes remote resources to database.
- magpie.cli.sync_resources._format_resource_tree(children: magpie.typedefs.ServiceResourceNodeTree) magpie.typedefs.RemoteResourceTree [source]¶
- magpie.cli.sync_resources._query_remote_resources_in_database(service_id: int, session: sqlalchemy.orm.session.Session) magpie.typedefs.RemoteResourceTree [source]¶
Reads remote resources from the RemoteResources table. No external request is made.
- Returns:
Dictionary of the form defined in
sync_services.is_valid_resource_schema()
.
- magpie.cli.sync_resources.get_last_sync(service_id: int, session: sqlalchemy.orm.session.Session) datetime.datetime | None [source]¶
Obtain the date-time of the last known sync event for a service.
- magpie.cli.sync_resources.fetch_all_services_by_type(service_type: magpie.typedefs.Str, session: sqlalchemy.orm.session.Session) None [source]¶
Get remote resources for all services of a certain type.
- Parameters:
service_type – Service type for which all corresponding services will be synchronized.
session – Database connexion to apply synchronization changes.
- magpie.cli.sync_resources.fetch_single_service(service: magpie.models.Service | int, session: sqlalchemy.orm.session.Session) None [source]¶
Get remote resources for a single service.
- Parameters:
service – Specific service for which to synchronize remote resources.
session – Database connexion to apply synchronization changes.
- magpie.cli.sync_resources.fetch(settings: magpie.typedefs.SettingsType | None = None) None [source]¶
Main function to get all remote resources for each service and write to database.