mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 14:06:36 +08:00
4f50f6a8f9
Wire plugin services through Bind/InjectFrom and AppContext so HTTP and workers resolve dependencies after Apply. Register TaskHandler objects with persisted results, and implement send_email_code, mail:send, cleanup_inactive_users, and dispatch_bot_msg.
38 lines
576 B
Go
38 lines
576 B
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package driver_inproc_worker
|
|
|
|
import (
|
|
"Wavelet/core"
|
|
"Wavelet/core/contracts"
|
|
"context"
|
|
"sync"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
var (
|
|
dbMu sync.RWMutex
|
|
dbSvc contracts.DBService
|
|
)
|
|
|
|
func setDBService(s contracts.DBService) {
|
|
dbMu.Lock()
|
|
defer dbMu.Unlock()
|
|
dbSvc = s
|
|
}
|
|
|
|
func getDB(ctx context.Context) *gorm.DB {
|
|
if s, err := core.InjectFrom[contracts.DBService](ctx); err == nil && s != nil {
|
|
return s.DB(ctx)
|
|
}
|
|
dbMu.RLock()
|
|
s := dbSvc
|
|
dbMu.RUnlock()
|
|
if s != nil {
|
|
return s.DB(ctx)
|
|
}
|
|
return nil
|
|
}
|