Files
mayan-edms/mayan/apps/checkouts/tasks.py
Roberto Rosario 8e69178e07 Project: Switch to full app paths
Instead of inserting the path of the apps into the Python app,
the apps are now referenced by their full import path.

This app name claves with external or native Python libraries.
Example: Mayan statistics app vs. Python new statistics library.

Every app reference is now prepended with 'mayan.apps'.

Existing config.yml files need to be updated manually.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2018-12-05 02:04:20 -04:00

34 lines
959 B
Python

from __future__ import unicode_literals
import logging
from django.apps import apps
from mayan.apps.lock_manager import LockError
from mayan.apps.lock_manager.runtime import locking_backend
from mayan.celery import app
from .literals import CHECKOUT_EXPIRATION_LOCK_EXPIRE
logger = logging.getLogger(__name__)
@app.task(ignore_result=True)
def task_check_expired_check_outs():
DocumentCheckout = apps.get_model(
app_label='checkouts', model_name='DocumentCheckout'
)
logger.debug('executing...')
lock_id = 'task_expired_check_outs'
try:
logger.debug('trying to acquire lock: %s', lock_id)
lock = locking_backend.acquire_lock(
name=lock_id, timeout=CHECKOUT_EXPIRATION_LOCK_EXPIRE
)
logger.debug('acquired lock: %s', lock_id)
DocumentCheckout.objects.check_in_expired_check_outs()
lock.release()
except LockError:
logger.debug('unable to obtain lock')