Skip to content

Commit e773188

Browse files
BCDA-9377: Remove init from main.go for api and worker (#1200)
## 🎫 Ticket https://jira.cms.gov/browse/BCDA-9377 ## 🛠 Changes - removed init from `bcda/main.go` and `bcdaworker/main.go`. - added directory setup to `bcdaworker/main_test.go` ## ℹ️ Context Part of ongoing effort to remove init to improve test suite. <!-- If any of the following security implications apply, this PR must not be merged without Stephen Walter's approval. Explain in this section and add @SJWalter11 as a reviewer. - Adds a new software dependency or dependencies. - Modifies or invalidates one or more of our security controls. - Stores or transmits data that was not stored or transmitted before. - Requires additional review of security implications for other reasons. --> ## 🧪 Validation Tests passing.
1 parent 62853bc commit e773188

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

bcda/main.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,25 @@ import (
4747
"github.com/CMSgov/bcda-app/log"
4848
)
4949

50-
func init() {
51-
log.SetupLoggers()
52-
client.SetLogger(log.BBAPI)
50+
func setupDirs() {
5351

5452
isEtlMode := conf.GetEnv("BCDA_ETL_MODE")
55-
if isEtlMode != "true" {
56-
createAPIDirs()
57-
} else {
53+
if isEtlMode == "true" {
54+
log.API.Info("BCDA application is running in ETL mode.")
5855
createETLDirs()
59-
}
60-
61-
if isEtlMode != "true" {
56+
} else {
6257
log.API.Info("BCDA application is running in API mode.")
6358
monitoring.GetMonitor()
64-
} else {
65-
log.API.Info("BCDA application is running in ETL mode.")
59+
createAPIDirs()
6660
}
61+
6762
}
6863

6964
func createAPIDirs() {
7065
archive := conf.GetEnv("FHIR_ARCHIVE_DIR")
7166
err := os.MkdirAll(archive, 0744)
7267
if err != nil {
73-
log.API.Fatal(err)
68+
log.API.Fatal(errors.Wrap(err, "Could not create CCLF file archive directory"))
7469
}
7570
}
7671

@@ -83,6 +78,9 @@ func createETLDirs() {
8378
}
8479

8580
func main() {
81+
log.SetupLoggers()
82+
client.SetLogger(log.BBAPI)
83+
setupDirs()
8684
app := bcdacli.GetApp()
8785
err := app.Run(os.Args)
8886
if err != nil {

bcdaworker/main.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ import (
2020
"github.com/sirupsen/logrus"
2121
)
2222

23-
func init() {
24-
createWorkerDirs()
25-
client.SetLogger(log.BBWorker)
26-
}
27-
2823
func createWorkerDirs() {
2924
staging := conf.GetEnv("FHIR_STAGING_DIR")
3025
err := os.MkdirAll(staging, 0744)
@@ -98,6 +93,8 @@ func waitForSig() {
9893
func main() {
9994
fmt.Println("Starting bcdaworker...")
10095
log.SetupLoggers()
96+
createWorkerDirs()
97+
client.SetLogger(log.BBWorker)
10198
db := database.Connect()
10299
healthChecker := health.NewHealthChecker(db)
103100
queue := queueing.StartRiver(db, utils.GetEnvInt("WORKER_POOL_SIZE", 4))

bcdaworker/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
func TestClearTempDirectory(t *testing.T) {
13+
createWorkerDirs()
1314
tempDirPrefix := conf.GetEnv("FHIR_TEMP_DIR")
1415
tempDir, err := os.MkdirTemp(tempDirPrefix, "bananas")
1516
defer os.RemoveAll(tempDir)

0 commit comments

Comments
 (0)