Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
This PR differentiates the access levels of the database among the various processes
Summary
This PR differentiates the access levels of the database among the various processes, and introduces two conventions.
crud.get_new_session(read_only=True)
crud.get_new_session(read_and_write=True)
to make changes to the database. Once all operations are complete, the process must release the lock usingcrud.release_db_lock
. By default, any other process trying to acquire the lock will wait for 60 seconds, after which it will returnFalse
..lock
, which contains information about the process id of the process which acquired the lock, and when the lock was acquired. When the lock is released, the file is deleted, and any other process can acquire the lock by creating a new file. This will allow multiple disparate processes to share the idea of locking of database writes, given that they follow the convention described above, and is fairly safe from race conditions given that we are unlikely to face high number of write requests at the same time.python -m openadapt.entrypoint
, there should be no lockfile, but just in case, running theentrypoint
module, cleans the lock file and starts anew, so special attention needs to be put here.Checklist
How can your code be run and tested?
Other information