Skip to content

Commit

Permalink
semaphor to handle dupe gitcoinbot submission
Browse files Browse the repository at this point in the history
  • Loading branch information
owocki committed Nov 2, 2018
1 parent 7869f0e commit 72d2860
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@
DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = env.bool('REDIS_LOG_IGNORED_EXCEPTIONS', default=True)
COLLECTFAST_CACHE = env('COLLECTFAST_CACHE', default='collectfast')
COLLECTFAST_DEBUG = env.bool('COLLECTFAST_DEBUG', default=False)
REDIS_URL = env('REDIS_URL', default='rediscache://redis:6379/0?client_class=django_redis.client.DefaultClient')

CACHES = {
'default': env.cache(
Expand Down
10 changes: 10 additions & 0 deletions app/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,13 @@ def get_default_network():
if settings.DEBUG:
return 'rinkeby'
return 'mainnet'


def get_semaphor(namespace, count=1):
from redis import Redis
from redis_semaphore import Semaphore
from urllib.parse import urlparse
redis = urlparse(settings.REDIS_URL)

semaphore = Semaphore(Redis(host=redis.hostname, port=redis.port), count=count, namespace=namespace)
return semaphore
16 changes: 10 additions & 6 deletions app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import ipfsapi
import requests
from app.utils import get_semaphor
from dashboard.helpers import UnsupportedSchemaException, normalize_url, process_bounty_changes, process_bounty_details
from dashboard.models import Activity, Bounty, UserAction
from eth_utils import to_checksum_address
Expand Down Expand Up @@ -319,14 +320,17 @@ def web3_process_bounty(bounty_data):
print(f"--*--")
return None

did_change, old_bounty, new_bounty = process_bounty_details(bounty_data)
semaphor_key = f"bounty_processor_{bounty_data['id']}"
semaphor = get_semaphor(semaphor_key)
with semaphor:
did_change, old_bounty, new_bounty = process_bounty_details(bounty_data)

if did_change and new_bounty:
_from = old_bounty.pk if old_bounty else None
print(f"- processing changes, {_from} => {new_bounty.pk}")
process_bounty_changes(old_bounty, new_bounty)
if did_change and new_bounty:
_from = old_bounty.pk if old_bounty else None
print(f"- processing changes, {_from} => {new_bounty.pk}")
process_bounty_changes(old_bounty, new_bounty)

return did_change, old_bounty, new_bounty
return did_change, old_bounty, new_bounty


def has_tx_mined(txid, network):
Expand Down
2 changes: 2 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ mkdocs-material==3.0.4
pydoc-markdown==2.0.4
oauth2client==4.1.3
pyvips==2.1.3
redis-semaphore

0 comments on commit 72d2860

Please sign in to comment.