Forum OpenACS Q&A: Re: Tracking actual traffic usage with ad_returnfile_background?

The probably cleanest way is to add a client_data to ad_returnfile_background and its supporting functions (i have committed this just now to cvs head). One can pass arbitrary data such as item_id, revision_id etc. to the send delivery operation, like in the following example:

# Call ad_returnfile background (e.g. in acs-content-repository/tcl/revision-procs.tcl)
# with some provided client_data.
set client_data [list item_id $item_id revision_id $revision_id \
       headers [ns_set array [ns_conn headers]]]
ad_returnfile_background -client_data $client_data 200 $mime_type $filename
Also the custom spooler receives the client_data option, which is per default empty. If data is provided at invocation time it can be evaluated in the custom spooler.
  Class customSpooler
  customSpooler instproc end-delivery {{-client_data ""} filename fd channel bytes args} {
    ns_log notice "CUSTOM end-delivery, bytes written = $bytes, client_data=$client_data"
With the sample settings provided, you should be able to get the object-ids and the request headers, etc. in the background thread in an extensible manner

All the best
-gustaf neumann