b54493f785
BE-3 observability: expose the worker's Prometheus metrics on :6060/metrics (apns/fcm/asynq histograms + a new cache_ops_total counter were recorded all along but never scraped — which is why those dashboard panels read empty); add the worker containerPort, the vmagent worker scrape job, and two additive NetworkPolicies. Instrument cache Get/Set hit/miss. BE-2 retention: three periodic Asynq cleanup crons mirroring the reminder-log cleanup — notifications (90d), webhook dedup log (180d), audit_log (365d). BE-1 GDPR data export: POST /api/auth/export/ enqueues a low-priority Asynq job that gathers all of the user's data (owned residences + their tasks/contractors/ documents/share-codes, plus profile/notifications/prefs/push-tokens/subscription/ audit log), zips one JSON file per category, and emails it as an attachment. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
package worker
|
|
|
|
import "encoding/json"
|
|
|
|
// Enqueuer defines the interface for enqueuing background email + notification
|
|
// tasks from the api request path. Implementations are expected to be cheap to
|
|
// call and non-blocking (Asynq's client batches over a persistent Redis
|
|
// connection).
|
|
type Enqueuer interface {
|
|
EnqueueWelcomeEmail(to, firstName, code string) error
|
|
EnqueueVerificationEmail(to, firstName, code string) error
|
|
EnqueuePasswordResetEmail(to, firstName, code, resetToken string) error
|
|
EnqueuePasswordChangedEmail(to, firstName string) error
|
|
EnqueueTaskCompletedNotification(taskID, completionID uint) error
|
|
EnqueueDataExport(userID uint) error
|
|
}
|
|
|
|
// Verify TaskClient satisfies the interface at compile time.
|
|
var _ Enqueuer = (*TaskClient)(nil)
|
|
|
|
// BuildDataExportPayload marshals a DataExportPayload to JSON bytes.
|
|
func BuildDataExportPayload(userID uint) ([]byte, error) {
|
|
return json.Marshal(DataExportPayload{UserID: userID})
|
|
}
|
|
|
|
// BuildWelcomeEmailPayload marshals a WelcomeEmailPayload to JSON bytes.
|
|
func BuildWelcomeEmailPayload(to, firstName, code string) ([]byte, error) {
|
|
return json.Marshal(WelcomeEmailPayload{
|
|
EmailPayload: EmailPayload{To: to, FirstName: firstName},
|
|
ConfirmationCode: code,
|
|
})
|
|
}
|
|
|
|
// BuildVerificationEmailPayload marshals a VerificationEmailPayload to JSON bytes.
|
|
func BuildVerificationEmailPayload(to, firstName, code string) ([]byte, error) {
|
|
return json.Marshal(VerificationEmailPayload{
|
|
EmailPayload: EmailPayload{To: to, FirstName: firstName},
|
|
Code: code,
|
|
})
|
|
}
|
|
|
|
// BuildPasswordResetEmailPayload marshals a PasswordResetEmailPayload to JSON bytes.
|
|
func BuildPasswordResetEmailPayload(to, firstName, code, resetToken string) ([]byte, error) {
|
|
return json.Marshal(PasswordResetEmailPayload{
|
|
EmailPayload: EmailPayload{To: to, FirstName: firstName},
|
|
Code: code,
|
|
ResetToken: resetToken,
|
|
})
|
|
}
|
|
|
|
// BuildPasswordChangedEmailPayload marshals an EmailPayload to JSON bytes.
|
|
func BuildPasswordChangedEmailPayload(to, firstName string) ([]byte, error) {
|
|
return json.Marshal(EmailPayload{To: to, FirstName: firstName})
|
|
}
|
|
|
|
// BuildTaskCompletedNotificationPayload marshals a TaskCompletedNotificationPayload
|
|
// to JSON bytes for the Asynq queue.
|
|
func BuildTaskCompletedNotificationPayload(taskID, completionID uint) ([]byte, error) {
|
|
return json.Marshal(TaskCompletedNotificationPayload{
|
|
TaskID: taskID,
|
|
CompletionID: completionID,
|
|
})
|
|
}
|