-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change postgres configuration in the producer to use the env vars fro…
…m the stack
- Loading branch information
1 parent
c20a92e
commit e461e26
Showing
14 changed files
with
105 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
{ | ||
"ScrapeConfiguration": { | ||
"StorageConnectionString": "", | ||
"Scrapers": [ | ||
{ | ||
"Name": "SyncEzTvJob", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
using Producer.Models.Configuration; | ||
|
||
namespace Producer.Extensions; | ||
|
||
public static class ConfigurationExtensions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/producer/Models/GithubConfiguration.cs → ...dels/Configuration/GithubConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Producer.Models; | ||
namespace Producer.Models.Configuration; | ||
|
||
public class GithubConfiguration | ||
{ | ||
|
29 changes: 29 additions & 0 deletions
29
src/producer/Models/Configuration/PostgresConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace Producer.Models.Configuration; | ||
|
||
public class PostgresConfiguration | ||
{ | ||
private const string Prefix = "POSTGRES"; | ||
private const string HostVariable = "HOST"; | ||
private const string UsernameVariable = "USER"; | ||
private const string PasswordVariable = "PASSWORD"; | ||
private const string DatabaseVariable = "DB"; | ||
private const string PortVariable = "PORT"; | ||
|
||
private string Host { get; init; } = Environment.GetEnvironmentVariable($"{Prefix}_{HostVariable}") ?? | ||
throw new InvalidOperationException($"Environment variable {Prefix}_{HostVariable} is not set"); | ||
|
||
private string Username { get; init; } = Environment.GetEnvironmentVariable($"{Prefix}_{UsernameVariable}") ?? | ||
throw new InvalidOperationException($"Environment variable {Prefix}_{UsernameVariable} is not set"); | ||
|
||
private string Password { get; init; } = Environment.GetEnvironmentVariable($"{Prefix}_{PasswordVariable}") ?? | ||
throw new InvalidOperationException($"Environment variable {Prefix}_{PasswordVariable} is not set"); | ||
|
||
private string Database { get; init; } = Environment.GetEnvironmentVariable($"{Prefix}_{DatabaseVariable}") ?? | ||
throw new InvalidOperationException($"Environment variable {Prefix}_{DatabaseVariable} is not set"); | ||
|
||
private int PORT { get; init; } = int.Parse( | ||
Environment.GetEnvironmentVariable($"{Prefix}_{PortVariable}") ?? | ||
throw new InvalidOperationException($"Environment variable {Prefix}_{PortVariable} is not set")); | ||
|
||
public string StorageConnectionString => $"Host={Host};Port={PORT};Username={Username};Password={Password};Database={Database};"; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/producer/Models/Configuration/RabbitMqConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace Producer.Models.Configuration; | ||
|
||
public class RabbitMqConfiguration | ||
{ | ||
public const string SectionName = "RabbitMqConfiguration"; | ||
public const string Filename = "rabbitmq.json"; | ||
|
||
public string? Host { get; set; } | ||
public string? Username { get; set; } | ||
public string? Password { get; set; } | ||
public string? QueueName { get; set; } | ||
public bool Durable { get; set; } | ||
public int MaxQueueSize { get; set; } | ||
public int MaxPublishBatchSize { get; set; } = 500; | ||
public int PublishIntervalInSeconds { get; set; } = 1000 * 10; | ||
|
||
public void Validate() | ||
{ | ||
if (MaxQueueSize == 0) | ||
{ | ||
return; | ||
} | ||
|
||
if (MaxQueueSize < 0) | ||
{ | ||
throw new InvalidOperationException("MaxQueueSize cannot be less than 0 in RabbitMqConfiguration"); | ||
} | ||
|
||
if (MaxPublishBatchSize < 0) | ||
{ | ||
throw new InvalidOperationException("MaxPublishBatchSize cannot be less than 0 in RabbitMqConfiguration"); | ||
} | ||
|
||
if (MaxPublishBatchSize > MaxQueueSize) | ||
{ | ||
throw new InvalidOperationException("MaxPublishBatchSize cannot be greater than MaxQueueSize in RabbitMqConfiguration"); | ||
} | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
src/producer/Models/ScrapeConfiguration.cs → ...dels/Configuration/ScrapeConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
namespace Producer.Models; | ||
namespace Producer.Models.Configuration; | ||
|
||
public class ScrapeConfiguration | ||
{ | ||
public const string SectionName = "ScrapeConfiguration"; | ||
public const string Filename = "scrapers.json"; | ||
|
||
public List<Scraper> Scrapers { get; set; } = []; | ||
public string StorageConnectionString { get; set; } = ""; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters