Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Usage
-q, --quiet Suppress all command output
--version show program's version number and exit
--report-all Report to Sentry even if the task has succeeded
--output-all Send all stderr/stdout output regardless of max
message length

The Sentry server address can also be specified through the SENTRY_DSN
environment variable (and the --dsn option can be omitted).
Expand Down
26 changes: 21 additions & 5 deletions cron_sentry/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
epilog=('The Sentry server address can also be specified through ' +
'the SENTRY_DSN environment variable ' +
'(and the --dsn option can be omitted).'),
usage='cron-sentry [-h] [--dsn SENTRY_DSN] [-M STRING_MAX_LENGTH] [--quiet] [--report-all] [--version] cmd [arg ...]',
usage='cron-sentry [-h] [--dsn SENTRY_DSN] [-M STRING_MAX_LENGTH] [--quiet] [--report-all] [--output-all] [--version] cmd [arg ...]',
)
parser.add_argument(
'--dsn',
Expand Down Expand Up @@ -54,6 +54,12 @@
default=False,
help='Report to Sentry even if the task has succeeded',
)
parser.add_argument(
'--output-all',
action='store_true',
default=False,
help='Send all stderr/stdout output regardless of max message length',
)
parser.add_argument(
'cmd',
nargs=REMAINDER,
Expand Down Expand Up @@ -125,7 +131,8 @@ def run(args=argv[1:]):
string_max_length=opts.string_max_length,
quiet=opts.quiet,
extra=_extra_from_env(environ),
report_all=opts.report_all
report_all=opts.report_all,
output_all=opts.output_all
)
sys.exit(runner.run())
else:
Expand All @@ -135,13 +142,14 @@ def run(args=argv[1:]):


class CommandReporter(object):
def __init__(self, cmd, dsn, string_max_length, quiet=False, extra=None, report_all=False):
def __init__(self, cmd, dsn, string_max_length, quiet=False, extra=None, report_all=False, output_all=False):
self.dsn = dsn
self.command = cmd
self.string_max_length = string_max_length
self.quiet = quiet
self.extra = {}
self.report_all = report_all
self.output_all = output_all
if extra is not None:
self.extra = extra

Expand All @@ -165,8 +173,12 @@ def run(self):
self.report(exit_status, last_lines_stdout, last_lines_stderr, elapsed)

if not self.quiet:
sys.stdout.write(last_lines_stdout)
sys.stderr.write(last_lines_stderr)
if self.output_all:
sys.stdout.write(self._get_all_lines(stdout))
sys.stderr.write(self._get_all_lines(stderr))
else:
sys.stdout.write(last_lines_stdout)
sys.stderr.write(last_lines_stderr)

return exit_status

Expand Down Expand Up @@ -210,3 +222,7 @@ def _get_last_lines(self, buf):
buf.seek(-(self.string_max_length - 3), SEEK_END)
last_lines = '...' + buf.read().decode('utf-8')
return last_lines

def _get_all_lines(self, buf):
buf.seek(0)
return buf.read().decode('utf-8')