Schedule outstanding orders
This commit is contained in:
parent
a057d1d281
commit
b1e3d24a54
4 changed files with 25 additions and 11 deletions
|
|
@ -35,9 +35,9 @@ class User(BaseModel):
|
|||
|
||||
def mastodon_account(self):
|
||||
if self.mastodon_server.name == MASTODON_INSTANCE:
|
||||
return f"@{self.mastodon_username}"
|
||||
return self.mastodon_username
|
||||
else:
|
||||
return f"@{self.mastodon_username}@{self.mastodon_server}"
|
||||
return f"{self.mastodon_username}@{self.mastodon_server}"
|
||||
|
||||
class Meta:
|
||||
table_name = 'user'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import datetime
|
||||
from peewee import JOIN, fn
|
||||
|
||||
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
|
||||
)
|
||||
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)
|
||||
)
|
||||
|
|
|
|||
12
orders.py
12
orders.py
|
|
@ -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 += "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':
|
||||
post += "⚠️ DEV"
|
||||
elif user.mastodon_attn_list:
|
||||
post += f"ATTN - {user.mastodon_attn_list}\n"
|
||||
|
||||
m = Mastodon(session)
|
||||
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 += punishment_str + "\n\n"
|
||||
|
||||
if user.mastodon_attn_list:
|
||||
post += f"ATTN - {user.mastodon_attn_list}\n"
|
||||
|
||||
if ENV == 'dev':
|
||||
post += "⚠️ DEV"
|
||||
elif user.mastodon_attn_list:
|
||||
post += f"ATTN - {user.mastodon_attn_list}\n"
|
||||
|
||||
m = Mastodon(session)
|
||||
return await m.statusPost(
|
||||
|
|
@ -186,7 +184,7 @@ async def order_check(order_status_id):
|
|||
for d in context['descendants']:
|
||||
if (
|
||||
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
|
||||
):
|
||||
confirmed_at = d['created_at']
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from scheduler.asyncio import Scheduler
|
|||
|
||||
from settings import TIMEZONE
|
||||
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
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -31,7 +31,12 @@ class OrderScheduler():
|
|||
)
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue