core.models.StorageShard module

Module with the StorageShard model class.

core.models.StorageShard.logger = <Logger core.models.StorageShard (INFO)>

The logger instance for this module.

class core.models.StorageShard.StorageShard(*args, **kwargs)[source]

Bases: ExportModelOperationsMixin('storage_shard'), TimestampModelMixin, Model

A database model to keep track of and manage the sharded storage’s status and structure.

Important

Use the custom methods to create new instances, never use create()!

shard_directory_name

The name of the directory tracked by this entry. Unique.

file_count

The number of files in this directory. 0 by default. Managed to not exceed constance.get_config('STORAGE_MAX_FILES_PER_DIR').

current

Flags whether this directory is the one where new data is being stored. False by default. There must only be one entry where this is set to True.

__str__()[source]

Returns a string representation of the model data.

Return type:

str

Returns:

The string representation of the storage directory, using path and the state of the directory.

save(*args, **kwargs)[source]

Extended :django:django.models.Model.save() method.

Safely creates the new directory tracked by the instance in the storage.

Return type:

None

Parameters:
exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

_meta = <Options for StorageShard>
created

The datetime the model instance was created. Is set automatically.

get_next_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)
get_next_by_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=True, **kwargs)
get_previous_by_created(*, field=<django.db.models.fields.DateTimeField: created>, is_next=False, **kwargs)
get_previous_by_updated(*, field=<django.db.models.fields.DateTimeField: updated>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

increment_file_count()[source]

Increments the file_count within the limits of constance.get_config('STORAGE_MAX_FILES_PER_DIR').

If the result exceeds this limit, creates a new storage directory via _add_shard().

Return type:

None

objects = <django.db.models.manager.Manager object>
updated

The datetime the model instance entry was last updated. Is set automatically.

decrement_file_count()[source]

Decrements the file_count but never below 0.

Return type:

None

classmethod get_current_storage()[source]

Gets the current storage instance.

Creates one if none is found.

Returns:

The currently used storage directory shard.

Return type:

StorageShard

classmethod _add_shard()[source]

Adds a new current storage directory.

Return type:

StorageShard

classmethod healthcheck()[source]

Provides a healthcheck for the storage.

Return type:

bool

Returns:

True if storage is healthy, False if there is no unique current storage directory or the count of files for one of the directories is wrong.