def set_daemon_timestamp(task_name, when): """ Set in the DB the current time associated with the given task; this is used to store a timestamp to know when the daemon run for the last time. :param task_name: the task for which we want to set the timestamp It has to be one of the keys of the ``aiida.backends.djsite.settings.settings.djcelery_tasks`` dictionary. :param when: can either be 'start' (to call when the task started) or 'stop' (to call when the task ended) """ from aiida.utils import timezone if when == 'start': verb = 'started' elif when == 'stop': verb = 'finished' else: raise ValueError("the 'when' parameter can only be 'start' or 'stop'") try: actual_task_name = celery_tasks[task_name] except KeyError: raise ValueError("Unknown value for 'task_name', not found in the " "djcelery_tasks dictionary") set_global_setting('daemon|task_{}|{}'.format(when, actual_task_name), timezone.datetime.now(tz=UTC), description=("The last time the daemon {} to run the " "task '{}' ({})" "".format(verb, task_name, actual_task_name)))
def set_global_setting(key, value, description=None): if settings.BACKEND == BACKEND_DJANGO: from aiida.backends.djsite.globalsettings import set_global_setting elif settings.BACKEND == BACKEND_SQLA: from aiida.backends.sqlalchemy.globalsettings import set_global_setting else: raise Exception("unknown backend {}".format(settings.BACKEND)) set_global_setting(key, value, description)
def set_daemon_user(user_email): """ Set the username (email) of the user that is allowed to run the daemon. """ from aiida.backends.djsite.globalsettings import set_global_setting set_global_setting("daemon|user", user_email, description="The only user that is allowed to run the " "AiiDA daemon on this DB instance")
def set_backend_type(backend_name): """ Set the schema version stored in the DB. Use only if you know what you are doing. """ return set_global_setting( 'db|backend', backend_name, description="The backend used to communicate with the database.")
def set_db_schema_version(version): """ Set the schema version stored in the DB. Use only if you know what you are doing. """ return set_global_setting( 'db|schemaversion', version, description="The version of the schema used in this database.")
def test_settings_methods(self): from aiida.backends.djsite.globalsettings import ( get_global_setting_description, get_global_setting, set_global_setting, del_global_setting) set_global_setting(key="aaa", value={'b': 'c'}, description="pippo") self.assertEqual(get_global_setting('aaa'), {'b': 'c'}) self.assertEqual(get_global_setting_description('aaa'), "pippo") self.assertEqual(get_global_setting('aaa.b'), 'c') self.assertEqual(get_global_setting_description('aaa.b'), "") del_global_setting('aaa') with self.assertRaises(KeyError): get_global_setting('aaa.b') with self.assertRaises(KeyError): get_global_setting('aaa')