I have all of my background tasks separated out and get called by other functions that are organized as ‘background task generators’, this way I can grab information about the task object before I return it to the client, or another function etc.
This way you could grab the id from the task object, store it in your data table, then return the task object to whatever called it to begin with (or send it nowhere, whatever).
Example server module:
blah blah background task decorated functions
functions that only create task objects with a call to the background tasks and return the task object
functions that do neither of the above things