Clean up orphaned tasks logs

Addresses #229

Without this, tasklogs will accumulate over time and eventually fill up
the master's disk.
tempfile import should go up above the `from module import foo` calls