cri_models.sync.engine module

class cri_models.sync.engine.SyncEngine(*args, **kwargs)[source]

Bases: object

Base class for synchronization engines

add_local_obj(local_obj_id, local_obj_data, *, pretend=False)[source]
add_remote_obj(remote_obj_id, remote_obj_data, *, pretend=False)[source]
bulk_add_local_objs(local_objs, *, pretend=False)[source]
bulk_add_remote_objs(remote_objs, *, pretend=False)[source]
bulk_delete_local_objs(local_objs, *, pretend=False)[source]
bulk_delete_remote_objs(remote_objs, *, pretend=False)[source]
bulk_update_objs(objs, *, pretend=False)[source]
delete_local_obj(local_obj_id, *, pretend=False)[source]
delete_remote_obj(remote_obj_id, *, pretend=False)[source]
get_obj_diff(local_obj_id, local_obj_data, remote_obj_id, remote_obj_data)[source]

Compare two existing objects and determines which fields need to be updated accordingly.

Returns

a mapping of field names to an (old_value, new_value) tuple.

sync(local_objects, remote_objects, obj_map, *, pretend=False)[source]
update_obj(local_obj_id, local_obj_data, remote_obj_id, remote_obj_data, *, pretend=False)[source]
class cri_models.sync.engine.UnidirectionalSyncEngine(*args, **kwargs)[source]

Bases: cri_models.sync.engine.SyncEngine

This synchronization engine always brings the remote objects to the state of the local objects.

sync(local_objects, remote_objects, obj_map, *, pretend=False)[source]

Synchronize objects.

The synchronization is done according to a three steps process:
  1. We remove the remote objects who are not related to a local objects.

  2. We create the missing remote objects for which a corresponding local objects exists.

  3. We update the remote objects for which a corresponding local objects exists.

Parameters
  • local_objects – a mapping between local objects ID and data

  • remote_objects – a mapping between remote objects ID and data

  • obj_map – a mapping between existing local objects IDs and existing remote objects IDs.

  • pretend – if True no action is effectively performed.

Returns

a tuple containing added, updated, deleted objects and failed operations