mentat.module.cleanup module

This Mentat module is a script providing database and cache cleanup functions and features.

This script is implemented using the pyzenkit.zenscript framework and so it provides all of its core features. See the documentation for more in-depth details.

It is further based on mentat.script.fetcher module, which provides database fetching and message post-processing capabilities.

Usage examples

# Display help message and exit. --help

# Run in debug mode (enable output of debugging information to terminal). --debug

# Run with increased logging level. --log-level debug

Available script commands

cleanup (default)

Perform cleanup of configured database collections and directory caches.

Custom configuration

Custom command line options

--db-path dir-name

Path to database files (for disk usage measurements).

Type: string, default: /var/lib/postgresql


Perform simulation, do not remove anything (flag).

Type: boolean, default: False

Available cleanup thresholds

  • 3y: items older than three years

  • 2y: items older than two years

  • y: items older than one year

  • 9m: items older than nine months

  • 6m: items older than six months

  • 4m: items older than four months

  • 3m: items older than three months

  • 16w: items older than sixteen weeks

  • 12w: items older than twelwe weeks

  • 8w: items older than eight weeks

  • 4w: items older than four weeks

  • 2w: items older than two weeks

  • w: items older than one week

  • 6d: items older than six days

  • 5d: items older than five days

  • 4d: items older than four days

  • 3d: items older than three days

  • 2d: items older than two days

  • d: items older than one day

  • 12h: items older than twelve hours

  • 8h: items older than eight hours

  • 6h: items older than six hours

  • 4h: items older than four hours

  • 3h: items older than three hours

  • 2h: items older than two hours

  • h: items older than one hour

class mentat.module.cleanup.MentatCleanupScript[source]

Bases: FetcherScript

Implementation of Mentat module (script) providing database and cache cleanup functions and features.

CONFIG_CACHES = 'caches'
CONFIG_DB_PATH = 'db_path'
CONFIG_EVENTS = 'events'
CONFIG_RUNLOGS = 'runlogs'
CONFIG_SIMULATE = 'simulate'
CONFIG_TABLES = 'tables'

Implementation of the cleanup command (default).

Perform cleanup of configured database collections and directory caches.


Return the name of the default script command. This command will be executed in case it is not explicitly selected either by command line option, or by configuration file directive.


Name of the default command.

Return type


mentat.module.cleanup.SECS_YEAR = 31556926

Number of seconds in a year (approximate).

mentat.module.cleanup.THRESHOLDS = {'12h': {'d': datetime.timedelta(seconds=43200), 'l': 'items older than twelve hours'}, '12w': {'d': datetime.timedelta(days=84), 'l': 'items older than twelve weeks'}, '16w': {'d': datetime.timedelta(days=112), 'l': 'items older than sixteen weeks'}, '2d': {'d': datetime.timedelta(days=2), 'l': 'items older than two days'}, '2h': {'d': datetime.timedelta(seconds=7200), 'l': 'items older than two hours'}, '2w': {'d': datetime.timedelta(days=14), 'l': 'items older than two weeks'}, '2y': {'d': datetime.timedelta(days=730, seconds=41852), 'l': 'items older than two years'}, '3d': {'d': datetime.timedelta(days=3), 'l': 'items older than three days'}, '3h': {'d': datetime.timedelta(seconds=10800), 'l': 'items older than three hours'}, '3m': {'d': datetime.timedelta(days=91, seconds=26831), 'l': 'items older than three months'}, '3y': {'d': datetime.timedelta(days=1095, seconds=62778), 'l': 'items older than three years'}, '4d': {'d': datetime.timedelta(days=4), 'l': 'items older than four days'}, '4h': {'d': datetime.timedelta(seconds=14400), 'l': 'items older than four hours'}, '4m': {'d': datetime.timedelta(days=121, seconds=64575), 'l': 'items older than four months'}, '4w': {'d': datetime.timedelta(days=28), 'l': 'items older than four weeks'}, '5d': {'d': datetime.timedelta(days=5), 'l': 'items older than five days'}, '6d': {'d': datetime.timedelta(days=6), 'l': 'items older than six days'}, '6h': {'d': datetime.timedelta(seconds=21600), 'l': 'items older than six hours'}, '6m': {'d': datetime.timedelta(days=182, seconds=53663), 'l': 'items older than six months'}, '8h': {'d': datetime.timedelta(seconds=28800), 'l': 'items older than eight hours'}, '8w': {'d': datetime.timedelta(days=56), 'l': 'items older than eight weeks'}, '9m': {'d': datetime.timedelta(days=273, seconds=80494), 'l': 'items older than nine months'}, 'd': {'d': datetime.timedelta(days=1), 'l': 'items older than one day'}, 'h': {'d': datetime.timedelta(seconds=3600), 'l': 'items older than one hour'}, 'w': {'d': datetime.timedelta(days=7), 'l': 'items older than one week'}, 'y': {'d': datetime.timedelta(days=365, seconds=20926), 'l': 'items older than one year'}}

List of possible cleanup thresholds.


Callback method for serializing objects into JSON.