Schedule outstanding orders

This commit is contained in:
Johnny Gear 2026-03-05 21:47:39 -06:00
parent a057d1d281
commit b1e3d24a54
4 changed files with 25 additions and 11 deletions

View file

@ -35,9 +35,9 @@ class User(BaseModel):
def mastodon_account(self): def mastodon_account(self):
if self.mastodon_server.name == MASTODON_INSTANCE: if self.mastodon_server.name == MASTODON_INSTANCE:
return f"@{self.mastodon_username}" return self.mastodon_username
else: else:
return f"@{self.mastodon_username}@{self.mastodon_server}" return f"{self.mastodon_username}@{self.mastodon_server}"
class Meta: class Meta:
table_name = 'user' table_name = 'user'

View file

@ -1,4 +1,5 @@
import datetime import datetime
from peewee import JOIN, fn
from .models import database, User, OrdersPool, DomSubUsers, Repeat, SkipDay, OrderStatus, MastodonServer from .models import database, User, OrdersPool, DomSubUsers, Repeat, SkipDay, OrderStatus, MastodonServer
@ -146,3 +147,13 @@ def order_status_confirm(id, confirmed_at):
OrderStatus.id == id OrderStatus.id == id
) )
return q.execute() return q.execute()
def order_status_outstanding():
Punishment = OrderStatus.alias()
return (OrderStatus
.select(OrderStatus)
.where(OrderStatus.due_at.is_null(False) & OrderStatus.confirmed_at.is_null())
.join(Punishment, JOIN.LEFT_OUTER, on=(OrderStatus.id == Punishment.punishment_for))
.group_by(OrderStatus)
.having(fn.COUNT(Punishment.id) == 0)
)

View file

@ -21,11 +21,10 @@ async def order_mastodon_post(session, orders_pool, orders_str, repeats, due_at)
post += f"These are the same orders from the last {repeats} days\n\n" post += f"These are the same orders from the last {repeats} days\n\n"
post += "Proof of compliance is due by " + due_at.strftime("%I:%M %p") + "\n\n" post += "Proof of compliance is due by " + due_at.strftime("%I:%M %p") + "\n\n"
if user.mastodon_attn_list:
post += f"ATTN - {user.mastodon_attn_list}\n"
if ENV == 'dev': if ENV == 'dev':
post += "⚠️ DEV" post += "⚠️ DEV"
elif user.mastodon_attn_list:
post += f"ATTN - {user.mastodon_attn_list}\n"
m = Mastodon(session) m = Mastodon(session)
return await m.statusPost(post) return await m.statusPost(post)
@ -112,11 +111,10 @@ async def punishment_mastodon_post(session, orders_pool, punishment_str, reply_i
post = "@%s has failed to post proof of compliance. Here is the punishment -\n\n" % user.mastodon_account() post = "@%s has failed to post proof of compliance. Here is the punishment -\n\n" % user.mastodon_account()
post += punishment_str + "\n\n" post += punishment_str + "\n\n"
if user.mastodon_attn_list:
post += f"ATTN - {user.mastodon_attn_list}\n"
if ENV == 'dev': if ENV == 'dev':
post += "⚠️ DEV" post += "⚠️ DEV"
elif user.mastodon_attn_list:
post += f"ATTN - {user.mastodon_attn_list}\n"
m = Mastodon(session) m = Mastodon(session)
return await m.statusPost( return await m.statusPost(
@ -186,7 +184,7 @@ async def order_check(order_status_id):
for d in context['descendants']: for d in context['descendants']:
if ( if (
d['in_reply_to_id'] == order_status.mastodon_id and d['in_reply_to_id'] == order_status.mastodon_id and
d['account']['username'] == order_status.user.mastodon_account() and d['account']['acct'] == order_status.user.mastodon_account() and
len(d['media_attachments']) > 0 len(d['media_attachments']) > 0
): ):
confirmed_at = d['created_at'] confirmed_at = d['created_at']

View file

@ -6,7 +6,7 @@ from scheduler.asyncio import Scheduler
from settings import TIMEZONE from settings import TIMEZONE
from orders import order_issue, order_check from orders import order_issue, order_check
from db.queries import orders_pool_by_id, orders_pool_scheduled, skip_day_contains from db.queries import orders_pool_by_id, orders_pool_scheduled, skip_day_contains, order_status_outstanding
from util import order_time from util import order_time
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -31,7 +31,12 @@ class OrderScheduler():
) )
self.outstanding_orders = {} self.outstanding_orders = {}
# TODO: Schedule outstanding order checks for order_status in order_status_outstanding():
self.outstanding_orders[order_status.id] = self.scheduler.once(
datetime.datetime.fromisoformat(order_status.due_at) + GRACE_PERIOD,
self.scheduled_check,
args=(order_status.id,)
)
# TODO: Schedule keeping schedule up to date # TODO: Schedule keeping schedule up to date