Skip to content

Commit 5b0c5c4

Browse files
committed
Add new method to check if a page is deleted.
1 parent 9fb11ea commit 5b0c5c4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

2stacks-page-check-for-deletion

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json
2+
import config
3+
import helpers
4+
5+
def lambda_handler(event, context):
6+
for record in event['Records']:
7+
callback_url = record['messageAttributes']['callback_url']['stringValue']
8+
wd_page_id = record['messageAttributes']['page_id']['stringValue']
9+
wikidot_site = record['messageAttributes']['wikidot_site']['stringValue']
10+
11+
logger.info(wd_page_id)
12+
data = {'page_id': wd_page_id, 'moduleName': 'pagerate/PageRateWidgetModule'}
13+
try:
14+
haystack = helpers.fetch(data, wikidot_site)
15+
except JSONDecodeError:
16+
# We get a 500 error back on an actually
17+
# deleted page which is exposed here as a JSON Decode error as we're
18+
# looking for the body of the message, which isn't passed to us.
19+
20+
# This is actually the only place we need to act because moved pages
21+
# are handled by SCUTTLE firing a get_page_metadata job on what it
22+
# sees as a 'new page.'
23+
24+
headers = {"Authorization": "Bearer " + config.scuttle_token, "Content-Type": "application/json"}
25+
r = requests.delete(callback_url + '/2stacks/page/delete/' + str(wd_page_id), headers=headers)
26+
27+
return { 'job': 'article_deleted' }
28+
return {
29+
'statusCode': 200,
30+
'body': json.dumps('Hello from Lambda!')
31+
}

0 commit comments

Comments
 (0)