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 logging
|
||||||
import datetime
|
import datetime
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from util import make_session
|
from util import make_session
|
||||||
from generate import generate_order, generate_punishment
|
from generate import generate_order, generate_punishment
|
||||||
|
|
@ -133,30 +134,32 @@ async def punishment_issue(session, outstanding_order):
|
||||||
punishment_str
|
punishment_str
|
||||||
)
|
)
|
||||||
|
|
||||||
|
order_check_lock = asyncio.Lock()
|
||||||
async def order_check():
|
async def order_check():
|
||||||
async with make_session() as session:
|
async with order_check_lock:
|
||||||
outstanding_orders = order_status_outstanding()
|
async with make_session() as session:
|
||||||
for outstanding_order in outstanding_orders:
|
outstanding_orders = order_status_outstanding()
|
||||||
m = Mastodon(session)
|
for outstanding_order in outstanding_orders:
|
||||||
context = await m.statusContext(outstanding_order.mastodon_id)
|
m = Mastodon(session)
|
||||||
|
context = await m.statusContext(outstanding_order.mastodon_id)
|
||||||
|
|
||||||
confirmed_at = None
|
confirmed_at = None
|
||||||
for d in context['descendants']:
|
for d in context['descendants']:
|
||||||
if (
|
if (
|
||||||
d['in_reply_to_id'] == outstanding_order.mastodon_id and
|
d['in_reply_to_id'] == outstanding_order.mastodon_id and
|
||||||
d['account']['username'] == MASTODON_USERNAME and
|
d['account']['username'] == MASTODON_USERNAME and
|
||||||
len(d['media_attachments']) > 0
|
len(d['media_attachments']) > 0
|
||||||
):
|
):
|
||||||
confirmed_at = d['created_at']
|
confirmed_at = d['created_at']
|
||||||
order_status_confirm(outstanding_order.id, confirmed_at)
|
order_status_confirm(outstanding_order.id, confirmed_at)
|
||||||
logger.info('Confirmed order %s' % (outstanding_order.id))
|
logger.info('Confirmed order %s' % (outstanding_order.id))
|
||||||
break
|
break
|
||||||
|
|
||||||
if confirmed_at is None:
|
if confirmed_at is None:
|
||||||
logger.info('Order %s remains unconfirmed' % (outstanding_order.id))
|
logger.info('Order %s remains unconfirmed' % (outstanding_order.id))
|
||||||
|
|
||||||
due_at = datetime.datetime.fromisoformat(outstanding_order.due_at)
|
due_at = datetime.datetime.fromisoformat(outstanding_order.due_at)
|
||||||
if(due_at < datetime.datetime.now(datetime.UTC)):
|
if(due_at < datetime.datetime.now(datetime.UTC)):
|
||||||
logger.info('Time to issue a punishment for %s' % outstanding_order.id)
|
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()
|
outstanding_orders = order_status_outstanding()
|
||||||
for oo in outstanding_orders:
|
for oo in outstanding_orders:
|
||||||
self.scheduler.once(
|
self.scheduler.once(
|
||||||
datetime.datetime.fromisoformat(oo['due_at']) + GRACE_PERIOD,
|
datetime.datetime.fromisoformat(oo.due_at) + GRACE_PERIOD,
|
||||||
self.scheduled_check
|
self.scheduled_check
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue