Skip to content

Commit c3734e0

Browse files
committed
feat: add history
1 parent fb2208d commit c3734e0

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

digibank/routes/integrations/tbank.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,23 @@ def tbank_recipe_salary_transfer():
227227
expirationTime = int(expirationTime.timestamp()) # convert to epoch, see https://stackoverflow.com/a/23004143/950462
228228

229229
# Let's continue...
230+
# Finally, re-queue with the new expiration time (TTL) e.g. current time + 1 month
231+
response1 = requests.post("https://api.ourfin.tech/recipes/create/lambda", json={
232+
"email": email,
233+
"taskName": taskName,
234+
"accountFrom": accountFrom,
235+
"accountTo": accountTo,
236+
"amount": amount,
237+
"creationTime": creationTime,
238+
"expirationTime": expirationTime,
239+
"taskSchedule": taskSchedule,
240+
"eventId": eventId,
241+
# to add in schedule
242+
})
243+
logger.info("{} requeued recurring DynamoDB TTL task through Lambda for {} {}".format(email, taskName, response1))
230244

231245
# First, find out transaction history
232-
response1 = requests.post("https://api.ourfin.tech/integrations/tbank/transaction_history")
246+
# response2 = requests.post("https://api.ourfin.tech/integrations/tbank/transaction_history")
233247

234248
# Look for keyword in transaction history's narrative
235249

@@ -241,18 +255,8 @@ def tbank_recipe_salary_transfer():
241255
"accountTo": accountTo,
242256
"amount": amount
243257
})
258+
logger.info("{} successfully completed {} {}".format(email, taskName, response2))
244259

245-
# Finally, re-queue with the new expiration time (TTL) e.g. current time + 1 month
246-
response3 = requests.post("https://api.ourfin.tech/recipes/create/lambda", json={
247-
"email": email,
248-
"taskName": taskName,
249-
"accountFrom": accountFrom,
250-
"accountTo": accountTo,
251-
"amount": amount,
252-
"creationTime": creationTime,
253-
"expirationTime": expirationTime
254-
# to add in schedule
255-
})
256260

257261
return jsonify({"status": 200, "message": "OK"}), 200
258262

digibank/routes/recipes.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def recipes_create_lambda():
5454

5555
email = data['email']
5656
taskName = data['taskName']
57+
eventId = data['eventId']
5758

5859
if taskName == "tbank.salary.transfer":
5960
accountFrom = data['accountFrom']
@@ -131,7 +132,8 @@ def recipes_create_lambda():
131132
},
132133
ExpressionAttributeValues={
133134
':data': {
134-
'task_name': taskName
135+
'task_name': taskName,
136+
'correlation_id': eventId,
135137
},
136138
':runTime': int(creationTime),
137139
},
@@ -230,3 +232,30 @@ def recipes_list():
230232
data.append(tmp)
231233

232234
return jsonify({"status": 200, "data": data}), 200
235+
236+
@app.route("/recipes/run_history", methods=['POST'])
237+
@requires_auth
238+
def recipes_run_history():
239+
# find out who's calling this endpoint
240+
token = get_token_auth_header()
241+
user_info = get_user_info(token)
242+
email = user_info['email']
243+
244+
# then get POSTed form data
245+
table = dynamodb.Table("scheduled_tasks_history")
246+
response = table.query(
247+
KeyConditionExpression=Key("email").eq(email)
248+
)
249+
data = []
250+
tz = pytz.timezone("Asia/Singapore")
251+
252+
for i in response['Items']:
253+
tmp = ast.literal_eval((json.dumps(i, cls=DecimalEncoder)))
254+
tmp['run_time'] = datetime.fromtimestamp(
255+
tmp['run_time'], tz).isoformat()
256+
257+
data.append(tmp)
258+
259+
data = sorted(data, key=lambda k: k['run_time'], reverse=True)
260+
261+
return jsonify({"status": 200, "data": data}), 200

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
aniso8601==7.0.0
12
astroid==2.4.2
23
atomicwrites==1.4.0
34
attrs==20.2.0
@@ -23,6 +24,7 @@ MarkupSafe==1.1.1
2324
mccabe==0.6.1
2425
packaging==20.4
2526
pluggy==0.13.1
27+
promise==2.3
2628
py==1.9.0
2729
pyasn1==0.4.8
2830
pycodestyle==2.6.0
@@ -36,6 +38,7 @@ python-jose==3.2.0
3638
pytz==2020.1
3739
requests==2.24.0
3840
rsa==4.6
41+
Rx==1.6.1
3942
s3transfer==0.3.3
4043
six==1.15.0
4144
toml==0.10.1

0 commit comments

Comments
 (0)