mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
fix: wait for publish logs before marking unavailable
This commit is contained in:
1 parent
70385bdc76
commit
31af7cf3c2
2 files changed
+62
-6
No files matched your search
@@ -27,6 +27,8 @@ let publishRequests = 0;
|
||||
let buildId = "build-1";
|
||||
let acceptedBuildId = "previous-build";
|
||||
let withHandle = true;
|
||||
let pendingLogResponses = 0;
|
||||
let failedLogResponses = 0;
|
||||
let holdLog:
|
||||
| { cursor?: number; response: ReturnType<typeof deferred<void>> }
|
||||
| undefined;
|
||||
@@ -90,6 +92,14 @@ beforeAll(async () => {
|
||||
"api.publish.getLog": async (value) => {
|
||||
const input = value as (typeof logRequests)[number];
|
||||
logRequests.push(input);
|
||||
if (pendingLogResponses > 0) {
|
||||
pendingLogResponses -= 1;
|
||||
return { availability: "pending" };
|
||||
}
|
||||
if (failedLogResponses > 0) {
|
||||
failedLogResponses -= 1;
|
||||
throw new Error("Temporary log failure");
|
||||
}
|
||||
const first = input.cursor === undefined;
|
||||
if (
|
||||
input.buildId === "build-1" &&
|
||||
@@ -154,6 +164,8 @@ beforeEach(() => {
|
||||
publishRequests = 0;
|
||||
logRequests.length = 0;
|
||||
withHandle = true;
|
||||
pendingLogResponses = 0;
|
||||
failedLogResponses = 0;
|
||||
holdLog = undefined;
|
||||
heldJob = undefined;
|
||||
heldPublish = undefined;
|
||||
@@ -296,6 +308,28 @@ test("a pending publish shows its local start time, then the runner time and dur
|
||||
expect(panel().textContent).not.toContain("Duration:");
|
||||
});
|
||||
|
||||
test("retries pending and failed log reads before giving up on the session", async () => {
|
||||
vi.useFakeTimers();
|
||||
pendingLogResponses = 1;
|
||||
failedLogResponses = 1;
|
||||
await render();
|
||||
await publish();
|
||||
await openReport();
|
||||
await act(async () => vi.waitFor(() => expect(logRequests).toHaveLength(1)));
|
||||
await act(async () => vi.advanceTimersByTimeAsync(5_000));
|
||||
await act(async () => vi.waitFor(() => expect(logRequests).toHaveLength(2)));
|
||||
await act(async () => vi.advanceTimersByTimeAsync(5_000));
|
||||
await waitFor(() =>
|
||||
expect(panel().querySelector("pre")?.textContent).toBe("€")
|
||||
);
|
||||
expect(logRequests.map(({ cursor }) => cursor)).toEqual([
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
1,
|
||||
]);
|
||||
});
|
||||
|
||||
test("Free does not fetch logs; upgrading reads UTF-8 from byte zero and preserves issue severity", async () => {
|
||||
await setPaid(false);
|
||||
await render();
|
||||
|
||||
@@ -64,6 +64,8 @@ type PublishProps = {
|
||||
};
|
||||
|
||||
const COUNTDOWN_DURATION = 60_000;
|
||||
const PUBLISH_LOG_RETRY_DELAY = 5_000;
|
||||
const PUBLISH_LOG_MAX_ATTEMPTS = 12;
|
||||
|
||||
const getPublishErrorFinding = (
|
||||
error: JSX.Element | string,
|
||||
@@ -531,20 +533,40 @@ export const PublishButton = ({ projectId }: PublishProps) => {
|
||||
const chunks: string[] = [];
|
||||
const issues: NonNullable<SessionPublish["issues"]> = [];
|
||||
let issuesOmitted = 0;
|
||||
let retryAttempts = 0;
|
||||
while (isReadCurrent()) {
|
||||
const result = await nativeClient.api.publish.getLog.query({
|
||||
projectId,
|
||||
buildId: item.buildId,
|
||||
logHandle: item.logHandle,
|
||||
cursor,
|
||||
});
|
||||
let result: Awaited<
|
||||
ReturnType<typeof nativeClient.api.publish.getLog.query>
|
||||
>;
|
||||
try {
|
||||
result = await nativeClient.api.publish.getLog.query({
|
||||
projectId,
|
||||
buildId: item.buildId,
|
||||
logHandle: item.logHandle,
|
||||
cursor,
|
||||
});
|
||||
} catch {
|
||||
result = { availability: "pending" };
|
||||
}
|
||||
if (isReadCurrent() === false) {
|
||||
return;
|
||||
}
|
||||
if (result.availability === "pending") {
|
||||
retryAttempts += 1;
|
||||
if (retryAttempts >= PUBLISH_LOG_MAX_ATTEMPTS) {
|
||||
update(item.buildId, { logState: "unavailable" });
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, PUBLISH_LOG_RETRY_DELAY)
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (result.availability !== "available") {
|
||||
update(item.buildId, { logState: "unavailable" });
|
||||
return;
|
||||
}
|
||||
retryAttempts = 0;
|
||||
update(item.buildId, {
|
||||
startedAt: result.startedAt ?? item.startedAt,
|
||||
completedAt: result.completedAt,
|
||||
|
||||
Reference in new issue
Block a user