kbr / autocron

Web-framework independent asynchronous task manager for delayed/cron-tasks with no dependencies beside the standard-library. Successor of autotask.
MIT License
0 stars 0 forks source link

sqlite3.OperationalError: unable to open database file #3

Closed jedie closed 3 weeks ago

jedie commented 1 month ago

I get on startup just:

  File "/home/jens/repos/django-for-runners/for_runners/apps.py", line 12, in ready
    autocron.start('autocron.db')  # activate autocron with his SQLite database
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jens/repos/django-for-runners/.venv/lib/python3.11/site-packages/autocron/__init__.py", line 36, in start
    _engine.start(database_file=database_file, workers=workers)
  File "/home/jens/repos/django-for-runners/.venv/lib/python3.11/site-packages/autocron/engine.py", line 132, in start
    if self.interface.is_worker_pid(pid):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jens/repos/django-for-runners/.venv/lib/python3.11/site-packages/autocron/sqlite_interface.py", line 107, in wrapper
    raise sqlite3.OperationalError(message)
sqlite3.OperationalError: unable to open database file

Seems to me, that autocron.configuration.Configuration._get_autocron_directory() will be never called! So the used parent directory ~.autocron/ will be not created.

kbr commented 1 month ago

In the upcoming 1.1.0 version (see development-branch) the configuration module is no longer present. But it could still be that the ~.autocron/ directory may not get created. Will go into this.

jedie commented 1 month ago

Think it's better to store the file as default into ~/.cache/

Maybe similar to https://github.com/requests-cache/requests-cache e.g.:

session = CachedSession(
    'demo_cache',
    use_cache_dir=True,                # Save files in the default user cache dir
)

This will result in the file: ~/.cache/demo_cache.sqlite

kbr commented 1 month ago

Technically ~/.cache/ would just be another path-name, but autocron stores not cached data but callables, payloads, results and also the configuration. On deleting a cache one would assume to lose some performance, but not real data. So from my point of view ~/.autocron/ is the proper location.

jedie commented 1 month ago

Maybe also a good option is to use https://pypi.org/project/platformdirs/ and use user_data_dir ?

kbr commented 1 month ago

Nice project - even know one maintainer. But beside that it is aimed for desktop applications it would end in using one opinionated location in favor for another opinionated location for the price of an additional dependency.