You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
xmrauctions/items/tasks/cleanup.py

29 lines
902 B
Python

from logging import getLogger
from datetime import timedelta
from django.utils import timezone as tz
from django.conf import settings
from huey import crontab
from huey.contrib.djhuey import periodic_task
from items.models import Item
from core.helpers.email_template import EmailTemplate
logger = getLogger('django.server')
@periodic_task(crontab(minute='0', hour='*/21'))
def close_stale_items():
time_delta = tz.now() - timedelta(days=settings.ESCROW_PERIOD_DAYS)
items = Item.objects.filter(list_date__lt=time_delta, available=True)
for item in items:
logger.info(f'[INFO] Found stale item #{item.id} (older than {settings.ESCROW_PERIOD_DAYS} days).')
if item.bids:
email_template = EmailTemplate(
item=item,
scenario='item_stale_with_bids',
role='seller'
)
email_template.send()