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

Thanks Gustaf,

I've upgraded to the CVS HEAD version of xotcl-core and retrieving the information works exactly as described (I even used to occation to install the request monitor which makes for a bit of fun as well.)

Now for my, hopefully, final question: Since the customSpooler runs only in the background thread, how do I transfer information about the request in the best manner. For example, I might was to log the object_id of the file returned. Or some information about the connection, such as the user's IP or the request referer. Obviously, ad_conn headers is not available by the time I get the finally tally of bytes downloaded and similarly I'm not able to do a global downloaded_object_id and then access that from the background thread.

Thank you for your input,
Steffen

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"
    next
  }
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