Skip to content

Commit

Permalink
click exit code support, code 3 for load errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wardi committed Oct 12, 2022
1 parent fef74ca commit bda19c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ckanapi/cli/ckan_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
short_help='Local API calls with ckanapi tool'
)
@click.argument('args', nargs=-1, type=click.UNPROCESSED)
def api(args):
@click.pass_context
def api(context, args):
from ckanapi.cli.main import main
import sys
sys.argv[1:] = args
return main(running_with_paster=True)
context.exit(main(running_with_paster=True) or 0)
5 changes: 5 additions & 0 deletions ckanapi/cli/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ def line_reader():
stats = completion_stats(processes)
pool = worker_pool(cmd, processes, line_reader())

failures = 0
with quiet_int_pipe() as errors:
for job_ids, finished, result in pool:
if not result:
# child exited with traceback
return 1
timestamp, action, error, response = json.loads(
result.decode('utf-8'))
if error:
failures += 1

if not arguments['--quiet']:
stderr.write(('%s %s %s %s %s %s\n' % (
Expand All @@ -110,6 +113,8 @@ def line_reader():
return 1
if 'interrupt' in errors:
return 2
if failures:
return 3


def load_things_worker(ckan, thing, arguments,
Expand Down

0 comments on commit bda19c1

Please sign in to comment.