Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retries with wait time but disable retries & wait time by default #21

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = defineConfig({
name: "anmeldung-berlin",
testDir: "./tests/",
timeout: 0,
retries: parseInt(process.env.RETRY_COUNT || "0"),
reporter: [["html", { open: "never" }]],
use: {
...devices["Desktop Chrome"],
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.match(/Rate limit exceeded/)) {
const waitSeconds = parseInt(process.env.RETRY_WAIT_SECONDS_BLOCKED || "0");
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