Skip to content

Commit

Permalink
Prepend PEERDB_DEPLOYMENT_UID only if its set (#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik authored Nov 28, 2023
1 parent ed514f4 commit fdd4979
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 11 additions & 0 deletions flow/connectors/utils/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ func GetEnvInt(name string, defaultValue int) int {

return i
}

// GetEnvString returns the value of the environment variable with the given name
// or defaultValue if the environment variable is not set.
func GetEnvString(name string, defaultValue string) string {
val, ok := GetEnv(name)
if !ok {
return defaultValue
}

return val
}
16 changes: 12 additions & 4 deletions flow/shared/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package shared

import (
"fmt"
"os"

"github.com/PeerDB-io/peer-flow/connectors/utils"
)

const (
Expand Down Expand Up @@ -34,13 +35,20 @@ const (
const FetchAndChannelSize = 256 * 1024

func GetPeerFlowTaskQueueName(taskQueueID TaskQueueID) (string, error) {
deploymentUID := os.Getenv("PEERDB_DEPLOYMENT_UID")
switch taskQueueID {
case PeerFlowTaskQueueID:
return deploymentUID + "-" + peerFlowTaskQueue, nil
return prependUIDToTaskQueueName(peerFlowTaskQueue), nil
case SnapshotFlowTaskQueueID:
return deploymentUID + "-" + snapshotFlowTaskQueue, nil
return prependUIDToTaskQueueName(snapshotFlowTaskQueue), nil
default:
return "", fmt.Errorf("unknown task queue id %d", taskQueueID)
}
}

func prependUIDToTaskQueueName(taskQueueName string) string {
deploymentUID := utils.GetEnvString("PEERDB_DEPLOYMENT_UID", "")
if deploymentUID == "" {
return taskQueueName
}
return fmt.Sprintf("%s-%s", deploymentUID, taskQueueName)
}

0 comments on commit fdd4979

Please sign in to comment.