handle ti.end by sending to database