Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

onboarding_steps: Retry with backoff when marking a step as read fails.

Prakhar Pratyush7a96ca24120c
diff --git a/web/src/onboarding_steps.ts b/web/src/onboarding_steps.ts
index 380f4c0cd3a..26769f2a6bf 100644
--- a/web/src/onboarding_steps.ts
+++ b/web/src/onboarding_steps.ts
@@ -4,7 +4,6 @@ import type * as z from "zod/mini";
import render_navigation_tour_video_modal from "../templates/navigation_tour_video_modal.hbs";
-import * as blueslip from "./blueslip.ts";
import * as channel from "./channel.ts";
import * as compose_recipient from "./compose_recipient.ts";
import * as dialog_widget from "./dialog_widget.ts";
@@ -18,10 +17,17 @@ export type OnboardingStep = z.output<typeof onboarding_step_schema>;
export const ONE_TIME_NOTICES_TO_DISPLAY = new Set<string>();
+const MAX_RETRIES = 5;
+
export function post_onboarding_step_as_read(
onboarding_step_name: string,
schedule_navigation_tour_video_reminder_delay?: number,
+ attempt = 1,
): void {
+ if (attempt > MAX_RETRIES) {
+ return;
+ }
+
const data: {onboarding_step: string; schedule_navigation_tour_video_reminder_delay?: number} =
{
onboarding_step: onboarding_step_name,
@@ -34,14 +40,23 @@ export function post_onboarding_step_as_read(
void channel.post({
url: "/json/users/me/onboarding_steps",
data,
- error(err) {
- if (err.readyState !== 0) {
- blueslip.error(`Failed to mark ${onboarding_step_name} as read.`, {
- readyState: err.readyState,
- status: err.status,
- body: err.responseText,
- });
+ error(xhr) {
+ if (xhr.status === 400) {
+ // Bad request: Codepath calling this function supplied
+ // invalid 'onboarding_step_name' (almost negligible chance
+ // because it's not user input) - but no point of retrying
+ // in that case.
+ return;
}
+
+ const retry_delay_secs = util.get_retry_backoff_seconds(xhr, attempt);
+ setTimeout(() => {
+ post_onboarding_step_as_read(
+ onboarding_step_name,
+ schedule_navigation_tour_video_reminder_delay,
+ attempt + 1,
+ );
+ }, retry_delay_secs * 1000);
},
});
}