rattail.datasync.rattail

DataSync for Rattail

class rattail.datasync.rattail.FromRattailToRattailBase(*args, **kwargs)[source]

Base class for Rattail -> Rattail datasync consumers

get_host_object(session, change)[source]

You must override this, to return a host object from the given DataSyncChange instance. Note that the host object need not be normalized, as that will be done by the importer. (This is effectively the only part of the processing which is not handled by the importer.)

get_importers()[source]

Returns a dictionary, keys of which are “model” names (e.g. 'Product') and values of which are Importer instances.

Note

The keys must ultimately align with the payload_type values, coming from the host system. Or at least that’s what will make life easy for the invoke_importer() method.

setup()[source]

This method is called when the consumer thread is first started.

class rattail.datasync.rattail.FromRattailToRattailExportConsumer(*args, **kwargs)[source]

Export data changes from “local” Rattail to another

begin_transaction()[source]

Called just before the consumer is asked to process changes, possibly via multiple batches.

commit_transaction()[source]

Called just after the consumer has successfully finished processing changes, possibly via multiple batches.

pre_process_changes(session, changes)[source]

Implement any “pre-processing” logic here.

Common example would be to establish DB connection to some external system(s).

In some rare cases you may also need to “sort” the changes, to ensure they are processed in a particular sequence.

Returns:

If you needed to modify the list of changes, you can return the new list. If this method returns None (which the default logic does) then the original set of changes will be processed.

rollback_transaction()[source]

Called when any batch of changes failed to process.

class rattail.datasync.rattail.FromRattailToRattailImportConsumer(*args, **kwargs)[source]

Import data changes from another Rattail to “local”

get_host_object(session, change)[source]

You must override this, to return a host object from the given DataSyncChange instance. Note that the host object need not be normalized, as that will be done by the importer. (This is effectively the only part of the processing which is not handled by the importer.)

process_changes(session, changes)[source]

Process all changes.

class rattail.datasync.rattail.RattailConsumer(*args, **kwargs)[source]

DataSync consumer for Rattail databases.

delete_instance(session, instance)[source]

Delete the given model instance from the given database session.

Subclasses may define model-specific methods instead of or in addition to overriding this generic one.

get_data_model()[source]

Subclasses may override this if they have extended the schema. Defaults to rattail.db.model.

merge_instance(session, instance)[source]

Merge the given model instance into the given database session.

Subclasses may define model-specific methods instead of or in addition to overriding this generic one.

merge_product(session, source_product)[source]

This method is somewhat of a hack, in order to properly handle rattail.db.model.Product instances and the interdependent nature of the related rattail.db.model.ProductPrice instances.

process_changes(host_session, changes)[source]

Process changes for a Rattail database.

class rattail.datasync.rattail.RattailWatcher(*args, **kwargs)[source]

DataSync watcher for Rattail databases.

get_changes(lastrun)[source]

Checks the Change table in a Rattail database, to see if there are any pending changes for the datasync daemon.

prune_changes(keys)[source]

Prune change records from the source database, if relevant.