-
Notifications
You must be signed in to change notification settings - Fork 26
/
track_bounty_expirations.py
35 lines (30 loc) · 1.24 KB
/
track_bounty_expirations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import time
from datetime import datetime, timezone
from django.core.management.base import BaseCommand
from notifications.notification_client import NotificationClient
from std_bounties.constants import ACTIVE_STAGE, EXPIRED_STAGE
from std_bounties.models import Bounty
import logging
logger = logging.getLogger('django')
notification_client = NotificationClient()
# TODO - This should just be a scheduled cronjob.
# There is no need to have this as a long running job
class Command(BaseCommand):
help = 'Listen for contract events'
def handle(self, *args, **options):
try:
while True:
expired_bounties = Bounty.objects.filter(
deadline__lt=datetime.now(timezone.utc),
bounty_stage=ACTIVE_STAGE
)
for bounty in expired_bounties:
bounty.bounty_stage = EXPIRED_STAGE
bounty.save()
bounty_state = bounty.record_bounty_state(bounty.deadline)
notification_client.bounty_expired(bounty.id, bounty.deadline, bounty_state[0].id)
time.sleep(60)
except Exception as e:
# goes to rollbar
logger.exception(e)
raise e