Skip to content

Stop browsers that weren't accessed in a long time.#41

Open
SvenMarcus wants to merge 5 commits intoslub:mainfrom
SvenMarcus:feature/stop-browsers
Open

Stop browsers that weren't accessed in a long time.#41
SvenMarcus wants to merge 5 commits intoslub:mainfrom
SvenMarcus:feature/stop-browsers

Conversation

@SvenMarcus
Copy link
Collaborator

I had a bit of time on my hand, so I implemented an initial idea for stopping browsers that weren't accessed in a long time to free up used ports.

Whenever a user opens a workspace, the server updates the access time of the corresponding background process.
The clean up is happening during our lifespan() function as an infinitely running async background task.

In order for this to work I added the methods update_access_time(browser) and browsers_accessed_before(time) to the repositories.
processtimeout.expiration_loop() is the background task called in the lifespan.

Note that in order to be able to test this functionality, I had to create a special lifetime for our tests, as the continuous loop would have prevented our tests from ever completing. You can find it in tests/ocrdmonitor/fixures/lifespan.py
It uses the same tasks as the production lifetime (found in ocrdmonitor/main.py), but with different arguments for expiration_loop to only loop once.

The timeout for browsers is configured in init.sh with the new environment variable OCRD_BROWSER__TIMEOUT.
Its value is a duration in ISO 8601 format as that is supported out of the box by pydantic (https://docs.pydantic.dev/latest/api/standard_library_types/#datetimetimedelta)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant