perform_work

        Process handler function for processing messages
        found in the ``multiprocessing.Manager.queue``

        Build the ``self.log_payload`` from the queued log messages
        and POST it to the Splunk endpoint

def perform_work(
            self):
        """perform_work

        Process handler function for processing messages
        found in the ``multiprocessing.Manager.queue``

        Build the ``self.log_payload`` from the queued log messages
        and POST it to the Splunk endpoint

        """

        self.debug_log((
            'perform_work - start'))

        self.tid = threading.current_thread().ident

        if self.sleep_interval > 0:
            # Stop the timer. Happens automatically if this is called
            # via the timer, does not if invoked by force_flush()
            if self.timer:
                self.timer.cancel()
            else:
                self.debug_log((
                    'perform_work - done - timer was destroyed'))
                return

        self.debug_log((
            'perform_work - ready tid={}').format(
                self.tid))

        try:

            not_done = not self.is_shutting_down(
                shutdown_event=self.shutdown_event)

            while not_done:

                try:
                    self.build_payload_from_queued_messages(
                        use_queue=self.queue,
                        shutdown_event=self.shutdown_event)
                except Exception as e:
                    if self.is_shutting_down(
                            shutdown_event=self.shutdown_event):
                        self.debug_log(
                            'perform_work - done - detected shutdown')
                    else:
                        self.debug_log((
                            'perform_work - done - '
                            'Exception shutting down with ex={}').format(
                                e))
                        self.shutdown()
                    self.already_done.set()
                    return
                # end of try to return if the queue

                self.publish_to_splunk()
                timer_interval = self.sleep_interval

                if not_done:
                    if self.is_shutting_down(
                            shutdown_event=self.shutdown_event):
                        self.debug_log(
                            'perform_work - done - shutdown detected')
                        self.already_done.set()
                        return
                    # check if done
                    else:
                        if self.num_sent > 0:
                            # run again if queue was not cleared
                            timer_interval = 0.5
                            self.debug_log(
                                'queue not empty - run again')
                        else:
                            self.debug_log(
                                'sleep={}s'.format(
                                    timer_interval))
                        time.sleep(timer_interval)
                # end of checking if this should run again or is shutting down

            # end of while not done

        except Exception as e:
            if self.is_shutting_down(
                    shutdown_event=self.shutdown_event):
                self.debug_log((
                    'perform_work - shutdown sent={}').format(
                        self.num_sent))
            else:
                self.debug_log((
                    'perform_work - ex={}').format(
                        e))
        # end of try/ex

        self.already_done.set()

        self.debug_log((
            'EXIT - perform_work - done - tid={}').format(
                self.tid))