Created
September 6, 2013 17:42
-
-
Save pcn/6467178 to your computer and use it in GitHub Desktop.
An alternative open_next_queue_file for the spooling carbon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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