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

24hr looppi vanhojen Sessioneiden poistoon | Antti/loop-for-deleting-expired-sessions #52

Merged
merged 12 commits into from
Nov 15, 2024

Conversation

anttiasmala
Copy link
Collaborator

Tässä prototyyppi loopista 😄

Copy link

vercel bot commented Nov 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lahjalista ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 15, 2024 10:44am

backend/utils.ts Outdated Show resolved Hide resolved
Comment on lines 50 to 55
// starts a interval that deletes expired sessions every 24 hours
// this is not awaited because it should not be mandatory to wait this getting ready
// old Sessions do not have a usage anyways
deleteExpiredSessionsLoop().catch((e) => {
console.error(e);
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En laittanut tätäkään awaitiin, koska ei kait tässä kannata odotuttaa turhaan. Vanhoilla Sessioneilla ei kuitenkaan ole enää varsinaista käyttöä, koska luodaan aina kirjautuessa uusi

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eikös tämä ole nyt tarpeeton, kun käytetään Vercelin cronia?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joo, oli tämäkin jäänyt poistamatta 😄

Copy link
Owner

@samuliasmala samuliasmala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tämä ei toimi Vercelissä sen serverless-toteutuksen takia. Tässä ChatGPT:n vastaus, joka selittää asian hyvin.

Maksimiaika setTimeoutlle hobby-planillä on 60 sekuntia.

Täältä löytyy ohjeet, miten tehdään Vercelin cron job.

@anttiasmala
Copy link
Collaborator Author

anttiasmala commented Nov 4, 2024

Tämä ei toimi Vercelissä sen serverless-toteutuksen takia. Tässä ChatGPT:n vastaus, joka selittää asian hyvin.

Maksimiaika setTimeoutlle hobby-planillä on 60 sekuntia.

Täältä löytyy ohjeet, miten tehdään Vercelin cron job.

Tein alunperin noilla Vercelin cron jobseilla, mutta tajusin etten pysty testaamaan toimiiko se (ei ilmeisesti toimi omalla koneella) 😄

ChatGPT:n vastaus oli hyvä 👍

@anttiasmala
Copy link
Collaborator Author

anttiasmala commented Nov 4, 2024

Tämä kommentti on vanhentunut

Tarvitseeko / kannattaako cron jobien API-endpoint suojata jotenkin? En netistä löytänyt suoraan vastausta

Lähinnä siksi, että jos sitä ei ole suojattu, periatteessa kuka tahansa voisi ajaa vanhojen Sessioneiden tyhjentäjäskriptin.

Normikäyttäjä ei endpointtia löydä, mutta boteilla on mahdollisuus.

Jos endpointtia ei suojata, olisiko hyvä lisätä jokin "cooldown", että kuinka usein skriptin voi ajaa? Tuolla estettäisiin "turha spämmi". Vai meneekö tämmöinen hifistelyksi? 😅

Edit: löyty Cron Jobien suojaukseen linkki: https://vercel.com/docs/cron-jobs/manage-cron-jobs#securing-cron-jobs

pages/api/cron/index.ts Outdated Show resolved Hide resolved
vercel.json Show resolved Hide resolved
@anttiasmala
Copy link
Collaborator Author

Nyt pitäisi olla lähempänä oikeaa. En pystynyt cron jobia testaamaan, mutta API:n pystyin. API itsessään toimi

Eli enää täytyy tietää onko yhteensopiva Vercelin kanssa ja toimiiko cron job 😄

Comment on lines 50 to 55
// starts a interval that deletes expired sessions every 24 hours
// this is not awaited because it should not be mandatory to wait this getting ready
// old Sessions do not have a usage anyways
deleteExpiredSessionsLoop().catch((e) => {
console.error(e);
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eikös tämä ole nyt tarpeeton, kun käytetään Vercelin cronia?

backend/utils.ts Outdated Show resolved Hide resolved

// if authHeader was correct we can delete expired sessions

await lucia.deleteExpiredSessions();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lisäisin tähän console.login, niin näkisi backendin lokeista helposti että cron toimii oikein.

Copy link
Owner

@samuliasmala samuliasmala Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lisäisin tähän console.login, niin näkisi backendin lokeista helposti että cron toimii oikein.

Tämä taisi jäädä lisäämättä?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joo tämä jäi, sori! Lisään heti! 👍

pages/api/cron/index.ts Show resolved Hide resolved
pages/api/cron/index.ts Outdated Show resolved Hide resolved
@anttiasmala
Copy link
Collaborator Author

Poistin deleteExpiredSessionsLoop:it (olin jossain branchissa nuo jo poistanut, koska näkyi terminaalin historiassa. En tiedä vain missä 🤣)

Mergesin mainin ja sitten kysymys koskien tuota Headersia


// if authHeader was correct we can delete expired sessions

await lucia.deleteExpiredSessions();
Copy link
Owner

@samuliasmala samuliasmala Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lisäisin tähän console.login, niin näkisi backendin lokeista helposti että cron toimii oikein.

Tämä taisi jäädä lisäämättä?

@anttiasmala anttiasmala merged commit 46e79c7 into main Nov 15, 2024
5 checks passed
@anttiasmala anttiasmala deleted the antti/loop-for-deleting-expired-sessions branch November 15, 2024 11:12
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

Successfully merging this pull request may close these issues.

Lisätään looppi, jolla poistetaan tietokannasta jo vanhentuneet Sessiot
2 participants