Skip to content

Commit

Permalink
Use Redis for locking
Browse files Browse the repository at this point in the history
Replace django-db-locking with Redis locks. This removes a dependency on
the former, but adds one on the latter.
  • Loading branch information
nielsvanoch authored and JonasSteur committed Dec 9, 2019
1 parent 8e3de7d commit 91675e5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ How to install:
'smsgateway.backends.smsextrapro.SmsExtraProBackend',
)

# The Redis used for locking the tasks
SMSGATEWAY_REDIS_URL = ''

* Some backends support incoming text messages:

# urls.py
Expand All @@ -35,4 +38,4 @@ How to install:
(r'^incoming_sms/$', backends.get_backend('mobileweb').handle_incoming),
)

* Set up your SMS gateway to use this url for incoming messages.
* Set up your SMS gateway to use this url for incoming messages.
4 changes: 1 addition & 3 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ Django>=2.1.5
django-statsd-unleashed>=1.0.1
statsd>=2.1.2

redis>=2.10.5
redis>=3.0.0
celery==4.0.2
kombu==4.0.2
billiard==3.5.0.2
amqp==2.1.4
vine==1.1.3
pytz>=2016.7

django-db-locking>=2.0.0

phonenumberslite==7.3.2

six>=1.11.0,<2.0
Expand Down
2 changes: 1 addition & 1 deletion smsgateway/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import absolute_import
__version__ = '2.1.21'
__version__ = '2.2.0'


def get_account(using=None):
Expand Down
5 changes: 3 additions & 2 deletions smsgateway/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from datetime import datetime
from logging import getLogger
from redis import ConnectionPool, Redis
from redis.lock import Lock
from waffle.models import Switch

from django.conf import settings
from celery import shared_task
from celery.utils.log import get_task_logger
from django_statsd.clients import statsd
from locking.models import NonBlockingLock

from smsgateway import get_account, send, send_queued
from smsgateway.backends.base import SMSBackend
Expand Down Expand Up @@ -41,7 +41,8 @@ def _send_smses(send_deferred=False, backend=None, limit=None):
else:
send_lock_name = 'smsgateway_send_sms'

with NonBlockingLock.objects.acquire_lock(lock_name=send_lock_name):
with Lock(redis=Redis.from_url(settings.SMSGATEWAY_REDIS_URL), name='smsgateway-' + send_lock_name,
blocking_timeout=0):
successes, failures = 0, 0
try:
# Get SMSes that need to be sent (deferred or non-deferred)
Expand Down

0 comments on commit 91675e5

Please sign in to comment.