-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5606 from gitcoinco/kevin/mint_token_requests_in_…
…celery mint kudos token requests (and redeem bulk kudos) in celery via a queue with retries, not on request/response cycle
- Loading branch information
Showing
8 changed files
with
126 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import time | ||
|
||
from app.redis_service import RedisService | ||
from celery import app | ||
from celery.utils.log import get_task_logger | ||
from dashboard.utils import get_web3 | ||
from hexbytes import HexBytes | ||
from kudos.models import KudosTransfer, TokenRequest | ||
|
||
logger = get_task_logger(__name__) | ||
|
||
redis = RedisService().redis | ||
|
||
# Lock timeout of 2 minutes (just in the case that the application hangs to avoid a redis deadlock) | ||
LOCK_TIMEOUT = 60 * 2 | ||
|
||
|
||
@app.shared_task(bind=True, max_retries=3) | ||
def mint_token_request(self, token_req_id, retry=False): | ||
""" | ||
:param self: | ||
:param token_req_id: | ||
:return: | ||
""" | ||
with redis.lock("tasks:token_req_id:%s" % token_req_id, timeout=LOCK_TIMEOUT): | ||
from kudos.management.commands.mint_all_kudos import sync_latest | ||
from dashboard.utils import has_tx_mined | ||
obj = TokenRequest.objects.get(pk=token_req_id) | ||
tx_id = obj.mint() | ||
if tx_id: | ||
while not has_tx_mined(tx_id, obj.network): | ||
time.sleep(1) | ||
sync_latest(0) | ||
sync_latest(1) | ||
sync_latest(2) | ||
sync_latest(3) | ||
else: | ||
self.retry(30) | ||
|
||
|
||
@app.shared_task(bind=True, max_retries=3) | ||
def redeem_bulk_kudos(self, kt_id, signed_rawTransaction, retry=False): | ||
""" | ||
:param self: | ||
:param kt_id: | ||
:param signed_rawTransaction: | ||
:return: | ||
""" | ||
with redis.lock("tasks:redeem_bulk_kudos:%s" % kt_id, timeout=LOCK_TIMEOUT): | ||
try: | ||
obj = KudosTransfer.objects.get(pk=kt_id) | ||
w3 = get_web3(obj.network) | ||
obj.txid = w3.eth.sendRawTransaction(HexBytes(signed_rawTransaction)).hex() | ||
obj.receive_txid = obj.txid | ||
obj.save() | ||
pass | ||
except Exception as e: | ||
self.retry(30) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters