Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locking mechanism to handle dupe gitcoinbot comments #2674

Merged
merged 1 commit into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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