Skip to content

Commit

Permalink
Add retries with wait time but disable retries & wait time by default
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-cortez-stevenson committed Jan 19, 2024
1 parent 50f9bd1 commit f4082a9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ MAILSLURP_API_KEY=*your-api-key* FORM_NAME=*your-name* FORM_PHONE=*your-phone-nu
APPOINTMENT_SERVICE="Abmeldung einer Wohnung" \
APPOINTMENT_EARLIEST_TIME="10:00 GMT" \
APPOINTMENT_LATEST_TIME="13:00 GMT" \
npm run debug
npm start
```

## Deployment

Set [playwright.config.js](/playwright.config.js) `retries` to a high number, if you want to run the app locally until a successful booking is made. You may very well be blocked for exceeding a rate limit. In this case, try setting `PROXY_URL` to a back-connect proxy URL.
### Local

Set [playwright.config.js](/playwright.config.js) `retries` to a high number (or run `npx playwright test --retries=*a high number* ...` from the CLI), if you want to run the app until a successful booking is made.

To increase your chances of getting an appointment, set `PROXY_URL` to a back-connect proxy URL.

If you don't have access to a back-connect proxy service, then I suggest setting environment variable `RETRY_WAIT_SECONDS` >= `90` to avoid exceeding the rate-limit and having to wait for `RETRY_WAIT_SECONDS_BLOCKED` to retry.

## Parameters

Expand Down Expand Up @@ -92,6 +98,8 @@ Variable | Default | Description
`LOGLEVEL` | "info" | Set to "debug" to get stdout.
`CONCURRENCY` | "16" | Max number of concurrent Pages.
`PROXY_URL` | `undefined` | Hide your IP with a back-connect proxy.
`RETRY_WAIT_SECONDS` | "0" | How long to wait between retries.
`RETRY_WAIT_SECONDS_BLOCKED` | "600" | How long to wait when rate-limited.

## Debugging

Expand Down
25 changes: 25 additions & 0 deletions tests/appointment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@ const test = require("../src/test.js")({
APPOINTMENT_LATEST_TIME: "23:59 GMT",
});

// eslint-disable-next-line no-empty-pattern
test.beforeEach(async ({}, testInfo) => {
if (testInfo.retry > 0) {
const waitSeconds = parseInt(process.env.RETRY_WAIT_SECONDS || "0");
logger.info(`Waiting ${waitSeconds} seconds then retrying ...`);
await sleep(waitSeconds * 1000);
}
});

test.afterEach(async ({ context }, testInfo) => {
await context.close()
if (testInfo.status !== testInfo.expectedStatus) {
logger.warn(`Appointment booking failed: ${testInfo.error.message}`);
if (testInfo.error.message === "Rate limit exceeded") {
const waitSeconds = parseInt(process.env.RETRY_WAIT_SECONDS_BLOCKED || "600");
logger.info(`Waiting ${waitSeconds} seconds because we were rate limited ...`);
await sleep(waitSeconds * 1000);
}
}
});

function sleep(ms = 120000) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

test("appointment", async ({ context, params }, testInfo) => {
logger.debug(JSON.stringify(params, null, 2));
const serviceURL = await getServiceURL(await context.newPage(), {
Expand Down

0 comments on commit f4082a9

Please sign in to comment.