-
Notifications
You must be signed in to change notification settings - Fork 1
feat: enrich feedback records with translated text #90
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
Merged
xernobyl
merged 17 commits into
feat/ENG-1254_tenant-settings-hub-language-enrichment
from
feat/ENG-1255_translate-feedback-records
Jun 25, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
753c025
feat: add translated-text columns to feedback records
xernobyl ea32cf5
feat: add translation config + tenant-settings cache
xernobyl fba6242
refactor: dedupe feedback-record scan + harden settings cache
xernobyl 4fd9b31
feat: add TranslationClient + OpenAI/Google factory
xernobyl 139948a
feat: add translation job args + enqueue provider
xernobyl 6d1ab20
feat: add feedback translation worker
xernobyl 8eee34f
fix: clear stale translations + compare script in source==target
xernobyl 2db33f8
fix: translation source-language handling + env docs
xernobyl b5b203a
feat: wire translation enrichment into the api and worker
xernobyl 2e2757f
feat: add translation backfill (command + service)
xernobyl 320e3b9
test: add translation worker pipeline integration tests
xernobyl 315b959
feat: add OpenTelemetry metrics to the translation pipeline
xernobyl eda00c4
fix: address review — not-found classification, cache disable, langKe…
xernobyl b0b84cf
feat: re-translate a tenant's records when its target_language changes
xernobyl 2aad26e
perf: stream the global translation backfill in keyset pages
xernobyl f28a09e
feat: snooze translation jobs on provider rate limits (429)
xernobyl 9227920
fix(translation): guard against stale-target overwrites in SetTransla…
xernobyl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| // backfill-translations enqueues River translation jobs for feedback records whose | ||
| // tenant has a target language configured and whose value_text is not yet translated | ||
| // to it (missing or stale). Run this one-off after enabling translation or changing a | ||
| // tenant's target language; hub-worker (or the API process) runs the jobs. | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "log/slog" | ||
| "os" | ||
|
|
||
| "github.com/riverqueue/river" | ||
| "github.com/riverqueue/river/riverdriver/riverpgxv5" | ||
|
|
||
| "github.com/formbricks/hub/internal/config" | ||
| "github.com/formbricks/hub/internal/repository" | ||
| "github.com/formbricks/hub/internal/service" | ||
| "github.com/formbricks/hub/internal/workers" | ||
| "github.com/formbricks/hub/pkg/database" | ||
| ) | ||
|
|
||
| var ( | ||
| errTranslationProviderRequired = errors.New("TRANSLATION_PROVIDER is required") | ||
| errTranslationModelRequired = errors.New("TRANSLATION_MODEL is required") | ||
| ) | ||
|
|
||
| const ( | ||
| defaultTranslationMaxAttempts = 3 | ||
| exitSuccess = 0 | ||
| exitFailure = 1 | ||
| ) | ||
|
|
||
| func main() { | ||
| os.Exit(run()) | ||
| } | ||
|
|
||
| func run() int { | ||
| cfg, err := config.Load() | ||
| if err != nil { | ||
| slog.Error("Failed to load configuration", "error", err) | ||
|
|
||
| return exitFailure | ||
| } | ||
|
|
||
| if cfg.Database.URL == "" || cfg.Database.URL == config.DefaultDatabaseURL { | ||
| slog.Error("DATABASE_URL must be set explicitly for this binary (do not use the default test URL)") | ||
|
|
||
| return exitFailure | ||
| } | ||
|
|
||
| if cfg.Translation.Provider == "" { | ||
| slog.Error(errTranslationProviderRequired.Error()) | ||
|
|
||
| return exitFailure | ||
| } | ||
|
|
||
| if cfg.Translation.Model == "" { | ||
| slog.Error(errTranslationModelRequired.Error()) | ||
|
|
||
| return exitFailure | ||
| } | ||
|
|
||
| maxAttempts := cfg.Translation.MaxAttempts | ||
| if maxAttempts <= 0 { | ||
| maxAttempts = defaultTranslationMaxAttempts | ||
| } | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| db, err := database.NewPostgresPool(ctx, cfg.Database.URL, | ||
| database.WithPoolConfig(cfg.Database.PoolConfig()), | ||
| ) | ||
| if err != nil { | ||
| slog.Error("Failed to connect to database", "error", err) | ||
|
|
||
| return exitFailure | ||
| } | ||
| defer db.Close() | ||
|
|
||
| translationCfg := service.TranslationClientConfig{ | ||
| Provider: cfg.Translation.Provider, | ||
| ProviderAPIKey: cfg.Translation.ProviderAPIKey, | ||
| Model: cfg.Translation.Model, | ||
| BaseURL: cfg.Translation.BaseURL, | ||
| GoogleCloudProject: cfg.Translation.GoogleCloudProject, | ||
| GoogleCloudLocation: cfg.Translation.GoogleCloudLocation, | ||
| } | ||
|
|
||
| translationClient, err := service.NewTranslationClient(ctx, translationCfg) | ||
| if err != nil { | ||
| slog.Error("Failed to create translation client", "error", err) | ||
|
|
||
| return exitFailure | ||
| } | ||
|
|
||
| repo := repository.NewFeedbackRecordsRepository(db) | ||
| feedbackRecordsService := service.NewFeedbackRecordsService(repo, nil, "", nil, nil, "", 0) | ||
|
|
||
| // Producer-only: we only enqueue jobs; workers run in hub-worker (or the API process). | ||
| // River requires the job kind registered (worker added) and MaxWorkers > 0 for a declared queue. | ||
| riverWorkers := river.NewWorkers() | ||
| river.AddWorker(riverWorkers, workers.NewFeedbackTranslationWorker(feedbackRecordsService, translationClient, nil)) | ||
|
|
||
| riverClient, err := river.NewClient(riverpgxv5.New(db), &river.Config{ | ||
| Queues: map[string]river.QueueConfig{ | ||
| service.TranslationsQueueName: {MaxWorkers: 1}, | ||
| }, | ||
| Workers: riverWorkers, | ||
| }) | ||
| if err != nil { | ||
| slog.Error("Failed to create River client", "error", err) | ||
|
|
||
| return exitFailure | ||
| } | ||
|
|
||
| enqueued, err := feedbackRecordsService.BackfillTranslations( | ||
| ctx, riverClient, service.TranslationsQueueName, maxAttempts) | ||
| if err != nil { | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| slog.Error("Backfill failed", "error", err) | ||
|
|
||
| return exitFailure | ||
| } | ||
|
|
||
| slog.Info("Backfill complete", "enqueued", enqueued) | ||
|
|
||
| fmt.Printf("Enqueued %d translation job(s).\n", enqueued) | ||
|
|
||
| return exitSuccess | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.