-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtasks.py
26 lines (19 loc) · 865 Bytes
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from celery.task.schedules import crontab
from celery.decorators import periodic_task
from django.utils import timezone
from models import Transaction, Rate, Allowance
def today():
return timezone.now().strftime('%m/%d/%Y')
@periodic_task(run_every=(crontab(minute=0, hour=0)), name="compute-rate", ignore_result=True)
def compute_rate():
balance = Rate.objects.total()
description = 'Rate Balance for {}'.format(today())
Transaction.objects.create(description=description, amount=balance)
@periodic_task(run_every=(crontab(0, 0, day_of_month='1')), name="compute-allowance", ignore_result=True)
def compute_allowance():
for allowance in Allowance.objects.all():
Transaction.objects.create(
description='Allowance for {}'.format(today()),
amount=allowance.amount,
allowance=allowance
)