gc3libs.persistence.store

class gc3libs.persistence.store.Persistable(*args, **kwargs)

A mix-in class to mark that an object should be persisted by its ID.

Any instance of this class is saved as an ‘external reference’ when a container holding a reference to it is saved.

class gc3libs.persistence.store.Store(url=None)

Interface for storing and retrieving objects on permanent storage.

Each save operation returns a unique “ID”; each ID is a Python string value, which is guaranteed to be temporally unique, i.e., no two save operations in the same persistent store can result in the same IDs being assigned to different objects. The “ID” is also stored in the instance attribute _id.

Any Python object can stored, provided it meets the following conditions:

  • it can be pickled with Python’s standard module pickle.
  • the instance attribute persistent_id is reserved for use by the Store class: it should not be set or altered by other parts of the code.
invalidate_cache()

Clear the loaded objects cache (if any).

Subsequent load() calls are guaranteed to re-load the data directly from the backing store.

list(**extra_args)

Return list of IDs of saved Job objects.

This is an optional method; classes that do not implement it should raise a NotImplementedError exception.

load(id_)

Load a saved object given its ID, and return it.

post_fork()

Restore functionality that was suspended in pre_fork()

This method will be called after forking/daemonizing has been successfully accomplished.

The default implementation of this method does nothing.

pre_fork()

Make preparations for fork()-ing the current process.

This should close open network connections or any other sockets or file descriptors that cannot be used by both the parent and child process.

The default implementation of this method does nothing; as of 2018-04-10, the only subclass making use of this functionality is SqlStore, which needs to dispose the SQLAlchemy engine and re-create it after forking.

remove(id_)

Delete a given object from persistent storage, given its ID.

replace(id_, obj)

Replace the object already saved with the given ID with a copy of obj.

save(obj)

Save an object, and return an ID.

gc3libs.persistence.store.make_store(uri, *args, **extra_args)

Factory producing concrete Store instances.

Given a URL and (optionally) initialization arguments, return a fully-constructed Store instance.

The only required argument is uri; if any other arguments are present in the function invocation, they are passed verbatim to the constructor associated with the scheme of the given uri.

Example:

>>> fs1 = make_store('file:///tmp')
>>> fs1.__class__.__name__
'FilesystemStore'

Argument uri can also consist of a path name, in which case a URL scheme ‘file:///’ is assumed:

>>> fs2 = make_store('/tmp')
>>> fs2.__class__.__name__
'FilesystemStore'
gc3libs.persistence.store.register(scheme, constructor)

Register constructor as the factory corresponding to an URL scheme.

If a different constructor is already registered for the same scheme, it is silently overwritten.

The registry mapping schemes to constructors is used in the make_store() to create concrete instances of gc3libs.persistence.Store, given a URI that identifies the kind and location of the storage.

Parameters:
  • scheme (str) – URL scheme to associate with the given constructor.
  • constructor (callable) – A callable returning a Store instance. Typically, a class constructor.