Skip to content

Commit 143275a

Browse files
committed
Update worker to use environment variables
1 parent 245c8f3 commit 143275a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

worker/src/Worker/Program.cs

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@ public static int Main(string[] args)
1616
{
1717
try
1818
{
19-
var pgsql = OpenDbConnection("Server=db;Username=postgres;Password=postgres;");
20-
var redisConn = OpenRedisConnection("redis");
19+
var sdEndpoint = Environment.GetEnvironmentVariable("COPILOT_SERVICE_DISCOVERY_ENDPOINT");
20+
21+
var pgUser = Environment.GetEnvironmentVariable("POSTGRES_USER");
22+
var pgPassword = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD");
23+
24+
var pgConn = "Server=db." + sdEndpoint + ";Username=" + pgUser + ";Password=" + pgPassword + ";";
25+
var redisHost = "redis." + sdEndpoint;
26+
27+
var pgsql = OpenDbConnection(pgConn);
28+
var redisConn = OpenRedisConnection(redisHost);
2129
var redis = redisConn.GetDatabase();
2230

2331
// Keep alive is not implemented in Npgsql yet. This workaround was recommended:
@@ -34,7 +42,7 @@ public static int Main(string[] args)
3442
// Reconnect redis if down
3543
if (redisConn == null || !redisConn.IsConnected) {
3644
Console.WriteLine("Reconnecting Redis");
37-
redisConn = OpenRedisConnection("redis");
45+
redisConn = OpenRedisConnection(redisHost);
3846
redis = redisConn.GetDatabase();
3947
}
4048
string json = redis.ListLeftPopAsync("votes").Result;
@@ -46,7 +54,7 @@ public static int Main(string[] args)
4654
if (!pgsql.State.Equals(System.Data.ConnectionState.Open))
4755
{
4856
Console.WriteLine("Reconnecting DB");
49-
pgsql = OpenDbConnection("Server=db;Username=postgres;Password=postgres;");
57+
pgsql = OpenDbConnection(pgConn);
5058
}
5159
else
5260
{ // Normal +1 vote requested

0 commit comments

Comments
 (0)