Skip to content
This repository has been archived by the owner on Sep 26, 2018. It is now read-only.

Subscriber balance zero out when validity expire (Client dependent) #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion cloud/endagaweb/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@
'task': 'endagaweb.tasks.usageevents_to_sftp',
# Run this at 15:00 UTC (10:00 PDT, 02:00 Papua time)
'schedule': crontab(minute=0, hour=17),
}
}, 'zero_out_subscribers_balance': {
'task': 'endagaweb.tasks.zero_out_subscribers_balance',
# Run this at 12:00 UTC (07:00 PDT, 12:00 Papua time).
'schedule': crontab(minute='0', hour=07),
},
})
19 changes: 18 additions & 1 deletion cloud/endagaweb/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from endagaweb.models import SystemEvent
from endagaweb.models import TimeseriesStat
from endagaweb.ic_providers.nexmo import NexmoProvider

from ccm.common import crdt

@app.task(bind=True)
def usageevents_to_sftp(self):
Expand Down Expand Up @@ -439,3 +439,20 @@ def req_bts_log(self, obj, retry_delay=60*10, max_retries=432):
raise
finally:
obj.save()


@app.task(bind=True)
def zero_out_subscribers_balance(self):
"""Subscriber balance zero outs when validity expires.

This runs this as a periodic task managed by celerybeat.
"""
today = django.utils.timezone.now()
subscribers = Subscriber.objects.filter(
valid_through__lte=today)
if not subscribers:
return # Do nothing
credit_balance = crdt.PNCounter("default").serialize()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to deal with crdt's. You can use the getter/setter Subscriber property balance

print "Validity expired for Susbcribers %s setting balance to 0" % (
[subscriber.imsi for subscriber in subscribers],)
subscribers.update(crdt_balance=credit_balance)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just update the value to zero?