mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
feat: add option sessionConnection for boltdb
This commit is contained in:
parent
d0e95bbcef
commit
3605bf25cd
3
.github/workflows/dev.yml
vendored
3
.github/workflows/dev.yml
vendored
@ -230,6 +230,9 @@ jobs:
|
||||
needs:
|
||||
- migrate-boltdb
|
||||
|
||||
env:
|
||||
SEMAPHORE_DB_OPTIONS: '{"sessionConnection": "true"}'
|
||||
|
||||
steps:
|
||||
- name: Checkout source
|
||||
uses: actions/checkout@v4
|
||||
|
@ -73,24 +73,7 @@ func (d *BoltDb) Migrate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *BoltDb) Connect(token string) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
if d.connections == nil {
|
||||
d.connections = make(map[string]bool)
|
||||
}
|
||||
|
||||
if _, exists := d.connections[token]; exists {
|
||||
// Use for debugging
|
||||
panic(fmt.Errorf("Connection " + token + " already exists"))
|
||||
}
|
||||
|
||||
if len(d.connections) > 0 {
|
||||
d.connections[token] = true
|
||||
return
|
||||
}
|
||||
|
||||
func (d *BoltDb) openDbFile() {
|
||||
var filename string
|
||||
if d.Filename == "" {
|
||||
config, err := util.Config.GetDBConfig()
|
||||
@ -110,11 +93,40 @@ func (d *BoltDb) Connect(token string) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *BoltDb) openSession(token string) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
if d.connections == nil {
|
||||
d.connections = make(map[string]bool)
|
||||
}
|
||||
|
||||
if _, exists := d.connections[token]; exists {
|
||||
// Use for debugging
|
||||
panic(fmt.Errorf("Connection " + token + " already exists"))
|
||||
}
|
||||
|
||||
if len(d.connections) > 0 {
|
||||
d.connections[token] = true
|
||||
return
|
||||
}
|
||||
|
||||
d.openDbFile()
|
||||
|
||||
d.connections[token] = true
|
||||
}
|
||||
|
||||
func (d *BoltDb) Close(token string) {
|
||||
func (d *BoltDb) Connect(token string) {
|
||||
if d.PermanentConnection() {
|
||||
d.openDbFile()
|
||||
} else {
|
||||
d.openSession(token)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *BoltDb) closeSession(token string) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
@ -139,8 +151,25 @@ func (d *BoltDb) Close(token string) {
|
||||
delete(d.connections, token)
|
||||
}
|
||||
|
||||
func (d *BoltDb) Close(token string) {
|
||||
if d.PermanentConnection() {
|
||||
if err := d.db.Close(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
d.closeSession(token)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *BoltDb) PermanentConnection() bool {
|
||||
return false
|
||||
config, err := util.Config.GetDBConfig()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
isSessionConnection, ok := config.Options["sessionConnection"]
|
||||
|
||||
return ok && (isSessionConnection == "true" || isSessionConnection == "yes")
|
||||
}
|
||||
|
||||
func (d *BoltDb) IsInitialized() (initialized bool, err error) {
|
||||
|
Loading…
Reference in New Issue
Block a user