execute function after session closes

Hi,

I wanted to send an email with the content of the annotations to my users (for some internal statistics they have to do) and i saw that in the on_exit function I can access the controller (which, working with the ?session parameter I asume I can access that parameter), but this functions only executes once when the server closes.
Is there any function that is called when a session closes?

There's not really a clear answer for what it means for a session to be "closed", so Prodigy currently doesn't track this. (It also generally tries to avoid any functionality that's too intrusive on the annotator client.) Like, does a session close when you close the browser tab? And what if you open it again with the same ?session marker, is that considered a new session start? What if a user just leaves the tab open and never closes it, does the session time out? These are all things that impact the decision you end up with.

One option would be to just add a button to the UI that the user can click to "end" their session explicitly, and it could then send the session ID and dataset ID to a custom endpoint, and that endpoint fetches the examples from the database and emails them. I've posted a super basic snippet for a button here:

The app.py that defines the endpoints is included in your Prodigy installation, so you could just hack in a new endpoint. Or you host your own microservice for it. It really just needs to access the general Prodigy database, so you don't necessarily need to define that code in your recipe – just any environment with Prodigy installed and access to the DB.

Thanks Ines

Yes my idea is that a session starts and ends with the tab, but i can see how using the session parameter could be difficult to use to extract only those from "the period of time of that tab was alive" as it overrides the get_session_id (at least for what i saw in the database) and it will send all the annotations that the user have made in all times.

I will take a look at that button, seems like it could work, another option I though was to implement it in the update / before_db functions, as they already need to save the work

One thing you could do is log the _task_hash values on the client and then send those back to your custom endpoint so you can filter the examples you fetch from the DB. You can listen to the prodigyanswer event on the client, which fires every time the annotator submits an answer and gives you access to the task object.

1 Like