Fix startup scheduling thing
This commit is contained in:
parent
3e1c780169
commit
70184112c1
2 changed files with 27 additions and 24 deletions
47
orders.py
47
orders.py
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import datetime
|
||||
import asyncio
|
||||
|
||||
from util import make_session
|
||||
from generate import generate_order, generate_punishment
|
||||
|
|
@ -133,30 +134,32 @@ async def punishment_issue(session, outstanding_order):
|
|||
punishment_str
|
||||
)
|
||||
|
||||
order_check_lock = asyncio.Lock()
|
||||
async def order_check():
|
||||
async with make_session() as session:
|
||||
outstanding_orders = order_status_outstanding()
|
||||
for outstanding_order in outstanding_orders:
|
||||
m = Mastodon(session)
|
||||
context = await m.statusContext(outstanding_order.mastodon_id)
|
||||
async with order_check_lock:
|
||||
async with make_session() as session:
|
||||
outstanding_orders = order_status_outstanding()
|
||||
for outstanding_order in outstanding_orders:
|
||||
m = Mastodon(session)
|
||||
context = await m.statusContext(outstanding_order.mastodon_id)
|
||||
|
||||
confirmed_at = None
|
||||
for d in context['descendants']:
|
||||
if (
|
||||
d['in_reply_to_id'] == outstanding_order.mastodon_id and
|
||||
d['account']['username'] == MASTODON_USERNAME and
|
||||
len(d['media_attachments']) > 0
|
||||
):
|
||||
confirmed_at = d['created_at']
|
||||
order_status_confirm(outstanding_order.id, confirmed_at)
|
||||
logger.info('Confirmed order %s' % (outstanding_order.id))
|
||||
break
|
||||
confirmed_at = None
|
||||
for d in context['descendants']:
|
||||
if (
|
||||
d['in_reply_to_id'] == outstanding_order.mastodon_id and
|
||||
d['account']['username'] == MASTODON_USERNAME and
|
||||
len(d['media_attachments']) > 0
|
||||
):
|
||||
confirmed_at = d['created_at']
|
||||
order_status_confirm(outstanding_order.id, confirmed_at)
|
||||
logger.info('Confirmed order %s' % (outstanding_order.id))
|
||||
break
|
||||
|
||||
if confirmed_at is None:
|
||||
logger.info('Order %s remains unconfirmed' % (outstanding_order.id))
|
||||
if confirmed_at is None:
|
||||
logger.info('Order %s remains unconfirmed' % (outstanding_order.id))
|
||||
|
||||
due_at = datetime.datetime.fromisoformat(outstanding_order.due_at)
|
||||
if(due_at < datetime.datetime.now(datetime.UTC)):
|
||||
logger.info('Time to issue a punishment for %s' % outstanding_order.id)
|
||||
due_at = datetime.datetime.fromisoformat(outstanding_order.due_at)
|
||||
if(due_at < datetime.datetime.now(datetime.UTC)):
|
||||
logger.info('Time to issue a punishment for %s' % outstanding_order.id)
|
||||
|
||||
await punishment_issue(session, outstanding_order)
|
||||
await punishment_issue(session, outstanding_order)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class OrderScheduler():
|
|||
outstanding_orders = order_status_outstanding()
|
||||
for oo in outstanding_orders:
|
||||
self.scheduler.once(
|
||||
datetime.datetime.fromisoformat(oo['due_at']) + GRACE_PERIOD,
|
||||
datetime.datetime.fromisoformat(oo.due_at) + GRACE_PERIOD,
|
||||
self.scheduled_check
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue