Skip to content
Closed
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
7 changes: 7 additions & 0 deletions src/lib/job-search/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ describe("requestJson", () => {
await expect(requestJson("JSEARCH", url)).rejects.toMatchObject({ problem: "changed" });
});

it("gives a source 30 seconds, as JSearch can take over 10 on a search it hasn't seen", async () => {
const timeout = vi.spyOn(AbortSignal, "timeout");
stubFetch(() => Response.json({ ok: true }));
await requestJson("JSEARCH", url);
expect(timeout).toHaveBeenCalledWith(30_000);
});

it("says it timed out when the source takes too long", async () => {
vi.spyOn(AbortSignal, "timeout").mockReturnValue(AbortSignal.abort());
stubFetch((_, signal) => Promise.reject(signal?.reason ?? new Error("aborted")));
Expand Down
4 changes: 3 additions & 1 deletion src/lib/job-search/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import type { JobSource } from "./search";
// fetching a posting (src/lib/posting-fetch.ts) there's no address to guard;
// requests are still limited in time and size.

export const REQUEST_TIMEOUT_MS = 10_000;
// JSearch can take over 10 seconds on a search it hasn't run before; the
// agent searches once a day, so a timeout there costs the whole run.
export const REQUEST_TIMEOUT_MS = 30_000;
const MAX_BYTES = 5 * 1024 * 1024;

/** GETs JSON from a source, turning every failure into a JobSearchError. */
Expand Down