• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

topfreegames / pitaya / 20349108963

18 Dec 2025 07:38PM UTC coverage: 61.46% (-0.5%) from 61.998%
20349108963

Pull #475

github

ffelipelimao
Implement IsReady method for Pitaya interface and related checks for service readiness
Pull Request #475: Implement IsReady method for Pitaya interface and related checks for …

0 of 42 new or added lines in 5 files covered. (0.0%)

19 existing lines in 2 files now uncovered.

5154 of 8386 relevant lines covered (61.46%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.64
/module.go
1
// Copyright (c) TFG Co. All Rights Reserved.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to deal
5
// in the Software without restriction, including without limitation the rights
6
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
// copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in all
11
// copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
// SOFTWARE.
20

21
package pitaya
22

23
import (
24
        "fmt"
25

26
        "github.com/topfreegames/pitaya/v2/interfaces"
27
        "github.com/topfreegames/pitaya/v2/logger"
28
)
29

30
type moduleWrapper struct {
31
        module interfaces.Module
32
        name   string
33
}
34

35
type sessionModuleWrapper struct {
36
        module interfaces.SessionModule
37
        name   string
38
}
39

40
// RegisterModule registers a module, by default it register after registered modules
41
func (app *App) RegisterModule(module interfaces.Module, name string) error {
1✔
42
        return app.RegisterModuleAfter(module, name)
1✔
43
}
1✔
44

45
// RegisterModuleAfter registers a module after all registered modules
46
func (app *App) RegisterModuleAfter(module interfaces.Module, name string) error {
1✔
47
        if err := app.alreadyRegistered(name); err != nil {
2✔
48
                return err
1✔
49
        }
1✔
50

51
        app.modulesMap[name] = module
1✔
52
        app.modulesArr = append(app.modulesArr, moduleWrapper{
1✔
53
                module: module,
1✔
54
                name:   name,
1✔
55
        })
1✔
56

1✔
57
        if sm, ok := module.(interfaces.SessionModule); ok {
1✔
58
                app.sessionModulesArr = append(app.sessionModulesArr, sessionModuleWrapper{
×
59
                        module: sm,
×
60
                        name:   name,
×
61
                })
×
62
        }
×
63

64
        return nil
1✔
65
}
66

67
// RegisterModuleBefore registers a module before all registered modules
68
func (app *App) RegisterModuleBefore(module interfaces.Module, name string) error {
1✔
69
        if err := app.alreadyRegistered(name); err != nil {
1✔
70
                return err
×
71
        }
×
72

73
        app.modulesMap[name] = module
1✔
74
        app.modulesArr = append([]moduleWrapper{
1✔
75
                {
1✔
76
                        module: module,
1✔
77
                        name:   name,
1✔
78
                },
1✔
79
        }, app.modulesArr...)
1✔
80

1✔
81
        if sm, ok := module.(interfaces.SessionModule); ok {
1✔
82
                app.sessionModulesArr = append([]sessionModuleWrapper{
×
83
                        {
×
84
                                module: sm,
×
85
                                name:   name,
×
86
                        },
×
87
                }, app.sessionModulesArr...)
×
88
        }
×
89

90
        return nil
1✔
91
}
92

93
// GetModule gets a module with a name
94
func (app *App) GetModule(name string) (interfaces.Module, error) {
1✔
95
        if m, ok := app.modulesMap[name]; ok {
2✔
96
                return m, nil
1✔
97
        }
1✔
98
        return nil, fmt.Errorf("module with name %s not found", name)
1✔
99
}
100

101
func (app *App) alreadyRegistered(name string) error {
1✔
102
        if _, ok := app.modulesMap[name]; ok {
2✔
103
                return fmt.Errorf("module with name %s already exists", name)
1✔
104
        }
1✔
105

106
        return nil
1✔
107
}
108

109
// startModules starts all modules in order
110
func (app *App) startModules() {
1✔
111
        logger.Log.Debug("initializing all modules")
1✔
112
        for _, modWrapper := range app.modulesArr {
2✔
113
                logger.Log.Debugf("initializing module: %s", modWrapper.name)
1✔
114
                if err := modWrapper.module.Init(); err != nil {
1✔
115
                        logger.Log.Fatalf("error starting module %s, error: %s", modWrapper.name, err.Error())
×
116
                }
×
117
        }
118

119
        for _, modWrapper := range app.modulesArr {
2✔
120
                modWrapper.module.AfterInit()
1✔
121
                logger.Log.Infof("module: %s successfully loaded", modWrapper.name)
1✔
122
        }
1✔
123
}
124

UNCOV
125
func (app *App) startModuleSessionDraining() {
×
UNCOV
126
        for i := len(app.sessionModulesArr) - 1; i >= 0; i-- {
×
127
                name := app.sessionModulesArr[i].name
×
128
                mod := app.sessionModulesArr[i].module
×
129

×
130
                logger.Log.Debugf("start session draining on module: %s", name)
×
131
                mod.StartSessionDraining()
×
132
        }
×
133
}
134

UNCOV
135
func (app *App) maxModuleSessionCount() int64 {
×
UNCOV
136
        count := int64(0)
×
UNCOV
137
        for _, mod := range app.sessionModulesArr {
×
138
                c := mod.module.SessionCount()
×
139
                if c > count {
×
140
                        count = c
×
141
                }
×
142
        }
UNCOV
143
        return count
×
144
}
145

146
// shutdownModules starts all modules in reverse order
147
func (app *App) shutdownModules() {
1✔
148
        for i := len(app.modulesArr) - 1; i >= 0; i-- {
2✔
149
                app.modulesArr[i].module.BeforeShutdown()
1✔
150
        }
1✔
151

152
        for i := len(app.modulesArr) - 1; i >= 0; i-- {
2✔
153
                name := app.modulesArr[i].name
1✔
154
                mod := app.modulesArr[i].module
1✔
155

1✔
156
                logger.Log.Debugf("stopping module: %s", name)
1✔
157
                if err := mod.Shutdown(); err != nil {
1✔
158
                        logger.Log.Warnf("error stopping module: %s", name)
×
159
                }
×
160
                logger.Log.Infof("module: %s stopped!", name)
1✔
161
        }
162
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc