Workisdone
snoop.data.management.commands.workisdone
#
Check if collection has finished processing.
Classes#
Command
#
Check if collection has finished processing.
Methods#
add_arguments(self, parser)
#
Single argument: the collection.
Source code in snoop/data/management/commands/workisdone.py
def add_arguments(self, parser):
"""Single argument: the collection."""
parser.add_argument('collection', type=str)
handle(self, collection, **options)
#
Looks at the snoop.data.models.Task table for any pending or deferred tasks.
Exists with return code 1
if such tasks exist, and 0
otherwise.
Source code in snoop/data/management/commands/workisdone.py
def handle(self, collection, **options):
"""Looks at the [snoop.data.models.Task][] table for any
[pending][snoop.data.models.Task.STATUS_PENDING] or
[deferred][snoop.data.models.Task.STATUS_DEFERRED] tasks.
Exists with return code `1` if such tasks exist, and `0` otherwise.
"""
logging_for_management_command(options['verbosity'])
col = collections.ALL[collection]
with col.set_current():
queryset = (
models.Task.objects
.filter(status__in=[
models.Task.STATUS_PENDING,
models.Task.STATUS_DEFERRED,
])
)
if queryset.first() is not None:
print("There are some pending or deferred tasks")
sys.exit(1)
print("There are no pending or deferred tasks")