コード例 #1
0
ファイル: crashmailbatch.py プロジェクト: hltbra/superlance
    def get_process_state_change_msg(self, headers, payload):
        pheaders, pdata = childutils.eventdata(payload+'\n')

        if int(pheaders['expected']):
            return None

        txt = 'Process %(groupname)s:%(processname)s (pid %(pid)s) died \
unexpectedly\n' % pheaders
        if self.stderr_lines:
            txt += get_last_lines_of_process_stderr(pheaders, self.stderr_lines)
        if self.stdout_lines:
            txt += get_last_lines_of_process_stdout(pheaders, self.stdout_lines)
        return '%s -- %s' % (childutils.get_asctime(self.now), txt)
コード例 #2
0
ファイル: fatalmailbatch.py プロジェクト: hltbra/superlance
    def get_process_state_change_msg(self, headers, payload):
        pheaders, pdata = childutils.eventdata(payload + "\n")

        txt = (
            "Process %(groupname)s:%(processname)s failed to start too many \
times\n"
            % pheaders
        )
        if self.stderr_lines:
            txt += get_last_lines_of_process_stderr(pheaders, self.stderr_lines)
        if self.stdout_lines:
            txt += get_last_lines_of_process_stdout(pheaders, self.stdout_lines)
        return "%s -- %s" % (childutils.get_asctime(self.now), txt)
コード例 #3
0
ファイル: crashmail.py プロジェクト: hltbra/superlance
    def runforever(self, test=False):
        while 1:
            # we explicitly use self.stdin, self.stdout, and self.stderr
            # instead of sys.* so we can unit test this code
            headers, payload = childutils.listener.wait(self.stdin, self.stdout)

            if not headers['eventname'] == 'PROCESS_STATE_EXITED':
                # do nothing with non-TICK events
                childutils.listener.ok(self.stdout)
                if test:
                    self.stderr.write('non-exited event\n')
                    self.stderr.flush()
                    break
                continue

            pheaders, pdata = childutils.eventdata(payload+'\n')

            if int(pheaders['expected']):
                childutils.listener.ok(self.stdout)
                if test:
                    self.stderr.write('expected exit\n')
                    self.stderr.flush()
                    break
                continue

            msg = ('Process %(processname)s in group %(groupname)s exited '
                   'unexpectedly (pid %(pid)s) from state %(from_state)s\n\n' %
                   pheaders)

            if self.stderr_lines:
                msg += get_last_lines_of_process_stderr(pheaders, self.stderr_lines)
            if self.stdout_lines:
                msg += get_last_lines_of_process_stdout(pheaders, self.stdout_lines)

            subject = ' %s crashed at %s' % (pheaders['processname'],
                                             childutils.get_asctime())
            if self.optionalheader:
                subject = self.optionalheader + ':' + subject

            self.stderr.write('unexpected exit, mailing\n')
            self.stderr.flush()

            self.mail(self.email, subject, msg)

            childutils.listener.ok(self.stdout)
            if test:
                break