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

cloudflare #14

Open
tst32 opened this issue Dec 11, 2021 · 1 comment
Open

cloudflare #14

tst32 opened this issue Dec 11, 2021 · 1 comment

Comments

@tst32
Copy link

tst32 commented Dec 11, 2021

https://github.com/vitalets/alice-renderer/blob/41836753b27b7fa252abb08e3e6e3e5dff236c5e/src/sessions.js
код session.js не работает в Cloudflare. подскажите как переписать?

Error: Something went wrong with the request to Cloudflare... Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request.

const startCleanupService = () => {

  if (cleanupTimer) {
     clearInterval(cleanupTimer);
  }
  cleanupTimer =  setInterval(cleanup, CLEANUP_INTERVAL);
  if (cleanupTimer.unref) {
    cleanupTimer.unref();
  }
};
@vitalets
Copy link
Owner

Ух, какое у них интересное ограничение!
Для облачных функций этот cleanupService вообще можно убрать, он больше нужен для постоянно живущих серверов, чтобы память не росла.
Сейчас самое простое решение - форкнуть и убрать этот код. А стейт для каждого пользователя читать и писать в сессии вручную. Я в я.функциях вот так делаю:

import { getSessions } from 'alice-renderer';

function loadRendererState() {
  const sessions: Map<string, Record<string, unknown>> = getSessions();
  sessions.set(userId, repliesState);
}

function saveRendererState() {
  const sessions: Map<string, Record<string, unknown>> = getSessions();
  const repliesState = sessions.get(userId);
  if (repliesState) putStateToResponse(userId, repliesState);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants