diff --git a/rattail/batch/__init__.py b/rattail/batch/__init__.py index e7d0924e4848bc18cba8ce5eec2c3f2a7d607bae..3a7d6f4a9a8cbc5c69f69e448ea03d2eaec027f2 100644 --- a/rattail/batch/__init__.py +++ b/rattail/batch/__init__.py @@ -27,3 +27,4 @@ Batch System from __future__ import unicode_literals, absolute_import from .handlers import BatchHandler, get_batch_handler +from .util import consume_batch_id diff --git a/rattail/batch/util.py b/rattail/batch/util.py index 2fde78a20c575c6db96cf49146d333f179d0aeae..fccbc066e4cec7cc64ff0196e8b332d6d45676c9 100644 --- a/rattail/batch/util.py +++ b/rattail/batch/util.py @@ -29,6 +29,14 @@ from __future__ import unicode_literals, absolute_import import inspect +def consume_batch_id(session): + """ + Consumes and returns the next batch ID from PG sequence. + """ + sql = "select nextval('batch_id_seq')" + return session.execute(sql).scalar() + + def get_batch_models(model): """ Returns a list of batch models available in the given ``model`` module.