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

Support RetryError in other functions #6860

Closed
mariusandra opened this issue May 25, 2021 · 3 comments
Closed

Support RetryError in other functions #6860

mariusandra opened this issue May 25, 2021 · 3 comments
Labels

Comments

@mariusandra
Copy link
Collaborator

PR PostHog/plugin-server#408 introduced RetryError, which you use like this:

import { RetryError } from '@posthog/plugin-scaffold' // also a global

export async function exportEvents (events, { global, config }) {
    try {
        await fetch(`https://${config.host}/e`, {
            method: 'POST',
            body: JSON.stringify(events),
            headers: { 'Content-Type': 'application/json' },
        })
    } catch (error) {
         throw new RetryError() // ask to retry
    }
}

This exportEvents function will now be automatically retried.

We should add the same functionality to onEvent, onSnapshot, and in the future perhaps also processEvent, though that's a bit trickier due to the ordering requirements.

Retries should also be something that's easy to add or automatic in other new functions like onAction, onRequest (incoming webhooks), etc.

@mariusandra
Copy link
Collaborator Author

One complication introduced by PostHog/plugin-server#408 is that the buffer.add call to enqueue events that eventually reach exportEvents is done in a patched onEvent. Basically:

const oldOnEvent = exports.oldOnEvent
exports.onEvent = (event, meta) => { buffer.add(event); oldOnEvent?.(event, meta) }

This messes up the retry logic a bit and should be split up nicely (as in don't retry the export when retrying the regular onEvent... it has its own retry handling).

@tiina303 tiina303 transferred this issue from PostHog/plugin-server Nov 3, 2021
@posthog-bot
Copy link
Contributor

This issue hasn't seen activity in two years! If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in two weeks.

@posthog-bot
Copy link
Contributor

This issue was closed due to lack of activity. Feel free to reopen if it's still relevant.

@posthog-bot posthog-bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2023
@github-project-automation github-project-automation bot moved this to Done This Sprint in Extensibility Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done This Sprint
Development

No branches or pull requests

2 participants