Skip to content

Commit a520b58

Browse files
committed
Consolidated loading bux
1 parent ce9bcd0 commit a520b58

3 files changed

Lines changed: 17 additions & 82 deletions

File tree

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ updates:
3232
- "chore"
3333
open-pull-requests-limit: 10
3434

35-
# Maintain dependencies for Docker (if used)
35+
# Maintain dependencies for Docker
3636
- package-ecosystem: "docker"
3737
target-branch: "master"
3838
directory: "/"

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
EnvironmentStaging = "staging"
2828
EnvironmentTest = "test"
2929
HealthRequestPath = "health"
30-
Version = "v0.1.5"
30+
Version = "v0.1.6"
3131
)
3232

3333
// Local variables for configuration

config/services.go

Lines changed: 15 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (a *AppConfig) LoadServices(ctx context.Context) (*AppServices, error) {
4444
defer txn.End()
4545

4646
// Load BUX
47-
if err = _services.loadBux(ctx, a); err != nil {
47+
if err = _services.loadBux(ctx, a, false); err != nil {
4848
return nil, err
4949
}
5050

@@ -69,7 +69,7 @@ func (a *AppConfig) LoadTestServices(ctx context.Context) (*AppServices, error)
6969
defer txn.End()
7070

7171
// Load bux for testing
72-
if err = _services.loadTestBux(ctx, a); err != nil {
72+
if err = _services.loadBux(ctx, a, true); err != nil {
7373
return nil, err
7474
}
7575

@@ -123,7 +123,7 @@ func (s *AppServices) CloseAll(ctx context.Context) {
123123
}
124124

125125
// loadBux will load the bux client (including CacheStore and DataStore)
126-
func (s *AppServices) loadBux(ctx context.Context, appConfig *AppConfig) (err error) {
126+
func (s *AppServices) loadBux(ctx context.Context, appConfig *AppConfig, testMode bool) (err error) {
127127
var options []bux.ClientOps
128128

129129
// Set new relic if enabled
@@ -168,6 +168,18 @@ func (s *AppServices) loadBux(ctx context.Context, appConfig *AppConfig) (err er
168168
options = append(options, bux.WithFreeCache())
169169
}
170170

171+
// Set the datastore options
172+
if testMode {
173+
// Set the unique table prefix
174+
if appConfig.SQLite.TablePrefix, err = utils.RandomHex(8); err != nil {
175+
return err
176+
}
177+
178+
// Defaults for safe thread testing
179+
appConfig.SQLite.MaxIdleConnections = 1
180+
appConfig.SQLite.MaxOpenConnections = 1
181+
}
182+
171183
// Set the datastore
172184
if options, err = loadDatastore(options, appConfig); err != nil {
173185
return err
@@ -234,83 +246,6 @@ func (s *AppServices) loadBux(ctx context.Context, appConfig *AppConfig) (err er
234246
return
235247
}
236248

237-
// loadTestBux will create a bux for testing purposes
238-
func (s *AppServices) loadTestBux(ctx context.Context, appConfig *AppConfig) (err error) {
239-
var options []bux.ClientOps
240-
241-
// New relic
242-
if appConfig.NewRelic.Enabled {
243-
options = append(options, bux.WithNewRelic(s.NewRelic))
244-
}
245-
246-
// Set if the feature is disabled
247-
if appConfig.DisableITC {
248-
options = append(options, bux.WithITCDisabled())
249-
}
250-
251-
// Custom user agent
252-
options = append(options, bux.WithUserAgent(appConfig.GetUserAgent()))
253-
254-
// Use in-memory caching
255-
options = append(options, bux.WithFreeCache())
256-
257-
// Use in-memory TaskQ
258-
// todo: read from JSON in buxServer config
259-
options = append(options, bux.WithTaskQ(
260-
// todo: use a custom queue name from the test or the appConfig?
261-
taskmanager.DefaultTaskQConfig(appConfig.Datastore.TablePrefix+"_queue"),
262-
taskmanager.FactoryMemory,
263-
))
264-
265-
// Turn on debugging
266-
if appConfig.Debug {
267-
options = append(options, bux.WithDebugging())
268-
}
269-
270-
// Set the unique table prefix
271-
if appConfig.SQLite.TablePrefix, err = utils.RandomHex(8); err != nil {
272-
return err
273-
}
274-
275-
// Defaults for safe thread testing
276-
appConfig.SQLite.MaxIdleConnections = 1
277-
appConfig.SQLite.MaxOpenConnections = 1
278-
279-
// Set the datastore
280-
if options, err = loadDatastore(options, appConfig); err != nil {
281-
return err
282-
}
283-
284-
// Load the notifications
285-
if appConfig.Notifications != nil && appConfig.Notifications.Enabled {
286-
options = append(options, bux.WithNotifications(appConfig.Notifications.WebhookEndpoint))
287-
}
288-
289-
// Load the monitor
290-
if appConfig.Monitor != nil && appConfig.Monitor.Enabled {
291-
if appConfig.Monitor.BuxAgentURL == "" {
292-
return errors.New("BUX Agent URL is required for monitoring")
293-
}
294-
options = append(options, bux.WithMonitoring(ctx, &chainstate.MonitorOptions{
295-
AuthToken: appConfig.Monitor.AuthToken,
296-
BuxAgentURL: appConfig.Monitor.BuxAgentURL,
297-
Debug: appConfig.Monitor.Debug,
298-
FalsePositiveRate: appConfig.Monitor.FalsePositiveRate,
299-
LoadMonitoredDestinations: appConfig.Monitor.LoadMonitoredDestinations,
300-
MaxNumberOfDestinations: appConfig.Monitor.MaxNumberOfDestinations,
301-
MonitorDays: appConfig.Monitor.MonitorDays,
302-
ProcessMempoolOnConnect: appConfig.Monitor.ProcessMempoolOnConnect,
303-
ProcessorType: appConfig.Monitor.ProcessorType,
304-
SaveTransactionDestinations: appConfig.Monitor.SaveTransactionDestinations,
305-
}))
306-
}
307-
308-
// Create the client
309-
s.Bux, err = bux.NewClient(ctx, options...)
310-
311-
return
312-
}
313-
314249
// loadDatastore will load the correct datastore based on the engine
315250
func loadDatastore(options []bux.ClientOps, appConfig *AppConfig) ([]bux.ClientOps, error) {
316251

0 commit comments

Comments
 (0)