Skip to content

Commit dd22280

Browse files
committed
fix hour check for verification interval; cast Number from sn admin ids; validate domain name only when there's one
1 parent 25674c2 commit dd22280

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

api/resolvers/domain.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
throw new GqlAuthenticationError()
3232
}
3333

34-
if (!SN_ADMIN_IDS.includes(me.id)) {
34+
if (!SN_ADMIN_IDS.includes(Number(me.id))) {
3535
throw new Error('not an admin')
3636
}
3737

@@ -44,16 +44,17 @@ export default {
4444
throw new GqlInputError('you do not own this sub')
4545
}
4646

47-
domainName = domainName.trim() // protect against trailing spaces
48-
await validateSchema(customDomainSchema, { domainName })
49-
5047
// we need to get the existing domain if we're updating or re-verifying
5148
const existing = await models.domain.findUnique({
5249
where: { subName },
5350
include: { records: true }
5451
})
5552

5653
if (domainName) {
54+
// validate the domain name
55+
domainName = domainName.trim() // protect against trailing spaces
56+
await validateSchema(customDomainSchema, { domainName })
57+
5758
// updating the domain name and recovering from HOLD is allowed
5859
if (existing && existing.domainName === domainName && existing.status !== 'HOLD') {
5960
throw new GqlInputError('domain already set')
@@ -126,13 +127,14 @@ export default {
126127

127128
// create the job to verify the domain in 30 seconds
128129
await tx.$executeRaw`
129-
INSERT INTO pgboss.job (name, data, retrylimit, retrydelay, startafter, keepuntil)
130+
INSERT INTO pgboss.job (name, data, retrylimit, retrydelay, startafter, keepuntil, singletonkey)
130131
VALUES ('domainVerification',
131132
jsonb_build_object('domainId', ${domain.id}::INTEGER),
132133
3,
133134
60,
134135
now() + interval '30 seconds',
135-
now() + interval '2 days'
136+
now() + interval '2 days',
137+
'domainVerification:' || ${domain.id}::TEXT -- domain <-> job isolation
136138
)`
137139

138140
return domain

components/territory-form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export default function TerritoryForm ({ sub }) {
289289
/>
290290
</div>
291291
</Form>
292-
{SN_ADMIN_IDS.includes(me.id) &&
292+
{SN_ADMIN_IDS.includes(Number(me.id)) &&
293293
<>
294294
{sub && !domain &&
295295
<div className='w-100'>

worker/domainVerification.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { verifyDNSRecord, issueDomainCertificate, checkCertificateStatus, getVal
33
import { datePivot } from '@/lib/time'
44

55
const VERIFICATION_INTERVAL = (updatedAt) => {
6-
const pivot = datePivot(new Date(), { hours: 1 }) // 1 hour ago
6+
const pivot = datePivot(new Date(), { hours: -1 }) // 1 hour ago
77
// after 1 hour, the verification interval is 5 minutes
88
if (pivot > updatedAt) return 60 * 5
99
// before 1 hour, the verification interval is 30 seconds
@@ -49,11 +49,11 @@ export async function domainVerification ({ id: jobId, data: { domainId }, boss
4949
// if it's not PENDING, we stop the verification process.
5050
if (result.status === 'PENDING') {
5151
// we still need to verify the domain, schedule the job to run again
52-
const newJobId = await boss.send('domainVerification', { domainId }, {
52+
const newJobId = await boss.sendDebounced('domainVerification', { domainId }, {
5353
startAfter: VERIFICATION_INTERVAL(domain.updatedAt),
5454
retryLimit: 3,
5555
retryDelay: 60 // on critical errors, retry every minute
56-
})
56+
}, 30, `domainVerification:${domainId}`)
5757
console.log(`domain ${domain.domainName} is still pending verification, created job with ID ${newJobId} to run in 5 minutes`)
5858
}
5959
} catch (error) {

0 commit comments

Comments
 (0)