Skip to content

Instantly share code, notes, and snippets.

@pcn
Created September 6, 2013 17:42
Show Gist options
  • Select an option

  • Save pcn/6467178 to your computer and use it in GitHub Desktop.

Select an option

Save pcn/6467178 to your computer and use it in GitHub Desktop.
An alternative open_next_queue_file for the spooling carbon
def open_next_queue_file(self):
"""While running this method contains the only operations that
will be run on the queue file. Opening the file this way will
close the old one and do whatever is necessary - either re-name
it if there is data, or remove it if there is no data.
"""
if self.queue_file:
size = self.queue_file.tell() # should be at the end of the file
self.queue_file.close()
if size == 0:
try:
os.unlink(self.queue_file_name)
except IOError:
# in case it was deleted by hand, no crying over spilt milk
# https://github.com/pcn/carbon/issues/15
pass
else:
os.rename(self.queue_file_name, new_name) # Tidy up
fname = os.path.basename(self.queue_file_name)
new_name = "{0}/{1}".format(self.send_queue_dir, fname)
log.clients("%s::open_next_queue_file new_name is {0}".format(self, new_name) )
self.queue_file_name = "{0}/{1:.2f}".format(self.send_tmp_dir, self.next_flush_time)
self.queue_file = open(self.queue_file_name, 'w')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment