Skip to content

Commit 444a5a0

Browse files
committed
feat: made image upload more resilient and improved fetch sponsor retries
1 parent 8e93b96 commit 444a5a0

File tree

3 files changed

+116
-113
lines changed

3 files changed

+116
-113
lines changed

functions/fetch-links/handler.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ export async function fetchLinks (event) {
4343
.subtract('1', 'week')
4444
.startOf('day')
4545

46-
const weekNumber = now.format('W')
47-
const year = now.format('YYYY')
48-
const campaignName = `fullstackBulletin-${weekNumber}-${year}`
46+
const nextIssue = event.NextIssue.number
47+
const campaignName = `fullstackBulletin-${nextIssue}`
4948

5049
console.log('Creating campaign', campaignName)
5150

functions/fetch-links/uploadImagesToCloudinary.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ const uploadImage = (client, imageUrl, publicId, hostname, stopRetry) =>
2222

2323
const uploadImageToCloudinary = (client, folder) => (urlInfo, cb) => {
2424
const publicId = `${folder}/${createHash('md5').update(urlInfo.image).digest('hex')}`
25-
const { hostname } = new URL(urlInfo.url)
25+
let hostname
26+
try {
27+
const url = new URL(urlInfo.url)
28+
hostname = url.hostname
29+
} catch (e) {
30+
const fallbackImage = `https://spaceholder.cc/i/600x400?r=${Math.random()}`
31+
return cb(null, { ...urlInfo, image: fallbackImage, originalImage: fallbackImage })
32+
}
2633
uploadImage(client, urlInfo.image, publicId, hostname)
2734
.then((info) => {
2835
const transformations = {

statemachine/create_issue.asl.yaml

Lines changed: 106 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,117 @@
11
Comment: Create a new issue of FullStack bulletin
22
StartAt: Define Defaults
33
States:
4-
Define Defaults:
5-
Type: Pass
6-
Next: Apply Defaults
7-
ResultPath: "$.defaults"
8-
Parameters:
9-
dryRun: false
10-
Apply Defaults:
11-
Type: Pass
12-
Next: Fetch Issue Number
13-
Parameters:
14-
config.$: "States.JsonMerge($.defaults, $$.Execution.Input, false)"
15-
Fetch Issue Number:
16-
Type: Task
17-
Resource: "${FetchIssueNumberFunctionArn}"
18-
Next: Fetch Data
19-
ResultPath: "$.NextIssue"
20-
Retry:
21-
- ErrorEquals:
4+
Define Defaults:
5+
Type: Pass
6+
Next: Apply Defaults
7+
ResultPath: $.defaults
8+
Parameters:
9+
dryRun: false
10+
Apply Defaults:
11+
Type: Pass
12+
Next: Fetch Issue Number
13+
Parameters:
14+
config.$: States.JsonMerge($.defaults, $$.Execution.Input, false)
15+
Fetch Issue Number:
16+
Type: Task
17+
Resource: ${FetchIssueNumberFunctionArn}
18+
Next: Fetch Data
19+
ResultPath: $.NextIssue
20+
Retry:
21+
- ErrorEquals:
22+
- Lambda.ServiceException
23+
- Lambda.AWSLambdaException
24+
- Lambda.SdkClientException
25+
- Lambda.TooManyRequestsException
26+
IntervalSeconds: 2
27+
MaxAttempts: 6
28+
BackoffRate: 2
29+
Fetch Data:
30+
Type: Parallel
31+
Next: Create Issue
32+
ResultSelector:
33+
Quote.$: $[0].Quote
34+
Book.$: $[1].Book
35+
Sponsor.$: $[2].Sponsor
36+
Links.$: $[3].Links
37+
ResultPath: $.data
38+
Branches:
39+
- StartAt: Fetch Quote
40+
States:
41+
Fetch Quote:
42+
Type: Task
43+
Resource: ${FetchQuoteFunctionArn}
44+
OutputPath: $
45+
ResultPath: $.Quote
46+
Retry:
47+
- ErrorEquals:
2248
- Lambda.ServiceException
2349
- Lambda.AWSLambdaException
2450
- Lambda.SdkClientException
2551
- Lambda.TooManyRequestsException
26-
IntervalSeconds: 2
27-
MaxAttempts: 6
28-
BackoffRate: 2
29-
Fetch Data:
30-
Type: Parallel
31-
Next: Create Issue
32-
ResultSelector:
33-
Quote.$: "$[0].Quote"
34-
Book.$: "$[1].Book"
35-
Sponsor.$: "$[2].Sponsor"
36-
Links.$: "$[3].Links"
37-
ResultPath: "$.data"
38-
Branches:
39-
- StartAt: Fetch Quote
40-
States:
41-
Fetch Quote:
42-
Type: Task
43-
Resource: "${FetchQuoteFunctionArn}"
44-
OutputPath: $
45-
ResultPath: $.Quote
46-
Retry:
47-
- ErrorEquals:
48-
- Lambda.ServiceException
49-
- Lambda.AWSLambdaException
50-
- Lambda.SdkClientException
51-
- Lambda.TooManyRequestsException
52-
IntervalSeconds: 2
53-
MaxAttempts: 6
54-
BackoffRate: 2
55-
End: true
56-
- StartAt: Fetch Book
57-
States:
58-
Fetch Book:
59-
Type: Task
60-
Resource: "${FetchBookFunctionArn}"
61-
OutputPath: $
62-
ResultPath: $.Book
63-
Retry:
64-
- ErrorEquals:
65-
- Lambda.ServiceException
66-
- Lambda.AWSLambdaException
67-
- Lambda.SdkClientException
68-
- Lambda.TooManyRequestsException
69-
IntervalSeconds: 2
70-
MaxAttempts: 6
71-
BackoffRate: 2
72-
End: true
73-
- StartAt: Fetch Sponsor
74-
States:
75-
Fetch Sponsor:
76-
Type: Task
77-
Resource: "${FetchSponsorFunctionArn}"
78-
OutputPath: $
79-
ResultPath: $.Sponsor
80-
Retry:
81-
- ErrorEquals:
82-
- Lambda.ServiceException
83-
- Lambda.AWSLambdaException
84-
- Lambda.SdkClientException
85-
- Lambda.TooManyRequestsException
86-
IntervalSeconds: 2
87-
MaxAttempts: 6
88-
BackoffRate: 2
89-
End: true
90-
- StartAt: Fetch Links
91-
States:
92-
Fetch Links:
93-
Type: Task
94-
Resource: "${FetchLinksFunctionArn}"
95-
OutputPath: $
96-
ResultPath: $.Links
97-
Retry:
98-
- ErrorEquals:
99-
- Lambda.ServiceException
100-
- Lambda.AWSLambdaException
101-
- Lambda.SdkClientException
102-
- Lambda.TooManyRequestsException
103-
IntervalSeconds: 2
104-
MaxAttempts: 6
105-
BackoffRate: 2
106-
End: true
107-
Create Issue:
108-
Type: Task
109-
Resource: "${CreateIssueFunctionArn}"
110-
OutputPath: $
111-
Retry:
112-
- ErrorEquals:
52+
IntervalSeconds: 2
53+
MaxAttempts: 6
54+
BackoffRate: 2
55+
End: true
56+
- StartAt: Fetch Book
57+
States:
58+
Fetch Book:
59+
Type: Task
60+
Resource: ${FetchBookFunctionArn}
61+
OutputPath: $
62+
ResultPath: $.Book
63+
Retry:
64+
- ErrorEquals:
11365
- Lambda.ServiceException
11466
- Lambda.AWSLambdaException
11567
- Lambda.SdkClientException
11668
- Lambda.TooManyRequestsException
117-
IntervalSeconds: 2
118-
MaxAttempts: 6
119-
BackoffRate: 2
120-
End: true
69+
IntervalSeconds: 2
70+
MaxAttempts: 6
71+
BackoffRate: 2
72+
End: true
73+
- StartAt: Fetch Sponsor
74+
States:
75+
Fetch Sponsor:
76+
Type: Task
77+
Resource: ${FetchSponsorFunctionArn}
78+
Retry:
79+
- ErrorEquals:
80+
- States.ALL
81+
IntervalSeconds: 3
82+
MaxAttempts: 3
83+
BackoffRate: 2
84+
OutputPath: $
85+
ResultPath: $.Sponsor
86+
End: true
87+
- StartAt: Fetch Links
88+
States:
89+
Fetch Links:
90+
Type: Task
91+
Resource: ${FetchLinksFunctionArn}
92+
OutputPath: $
93+
ResultPath: $.Links
94+
Retry:
95+
- ErrorEquals:
96+
- Lambda.ServiceException
97+
- Lambda.AWSLambdaException
98+
- Lambda.SdkClientException
99+
- Lambda.TooManyRequestsException
100+
IntervalSeconds: 2
101+
MaxAttempts: 6
102+
BackoffRate: 2
103+
End: true
104+
Create Issue:
105+
Type: Task
106+
Resource: ${CreateIssueFunctionArn}
107+
OutputPath: $
108+
Retry:
109+
- ErrorEquals:
110+
- Lambda.ServiceException
111+
- Lambda.AWSLambdaException
112+
- Lambda.SdkClientException
113+
- Lambda.TooManyRequestsException
114+
IntervalSeconds: 2
115+
MaxAttempts: 6
116+
BackoffRate: 2
117+
End: true

0 commit comments

Comments
 (0)