Exemple #1
0
    def timeout_callback(self):
        """
        On timeout expiration check if the job process is still running, and
        act accordingly if not.
        """
        if not supervising.is_pid_running(self.pid):
            logging.info('Process %s not running', self.pid)

            # see what status was left in the database by the exited job
            job_status = get_job_status(self.job_id)

            if job_status == 'succeeded':
                signalling.signal_job_outcome(self.job_id, 'succeeded')
            else:
                signalling.signal_job_outcome(self.job_id, 'failed')

                if job_status == 'running':
                    # The job crashed without having a chance to update the
                    # status in the database.  We do it here.
                    update_job_status_and_error_msg(self.job_id, 'failed',
                                                    'crash')

            cleanup_after_job(self.job_id)

            raise StopIteration
    def test_signalling(self):
        """
        Test connecting to the server, binding a queue to the signalling
        exchange and signalling the outcome of a job.
        """

        # Create the exchange and bind a queue to it
        conn, ch = signalling.connect()

        qname = signalling.declare_and_bind_queue(0, ('succeeded',))

        # Send a message
        signalling.signal_job_outcome(0, 'succeeded')

        messages = []

        def callback(msg):
            messages.append(msg)
            ch.basic_cancel(msg.consumer_tag)

        ch.basic_consume(qname, callback=callback)

        while ch.callbacks:
            ch.wait()

        ch.close()
        conn.close()

        self.assertEqual(1, len(messages))
Exemple #3
0
    def message_callback(self, msg):
        """
        Handles messages of severe level from the supervised job.
        """
        terminate_job(self.pid)

        signalling.signal_job_outcome(self.job_id, 'failed')

        update_job_status_and_error_msg(self.job_id, 'failed', msg.body)

        cleanup_after_job(self.job_id)

        raise StopIteration