Move EnvVars to Constants.cs

Add CHECK_CHAPTERS_BEFORE_START
This commit is contained in:
2025-10-03 20:15:55 +02:00
parent 5f8eed1867
commit 71d5116323
5 changed files with 24 additions and 8 deletions

View File

@@ -7,4 +7,13 @@ public struct Constants
public static readonly Size ImageSmSize = new (225, 320);
public static readonly Size ImageMdSize = new (450, 640);
public static readonly Size ImageLgSize = new (900, 1280);
public static readonly string PostgresHost = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "tranga-pg:5432";
public static readonly string PostgresDb = Environment.GetEnvironmentVariable("POSTGRES_DB") ?? "postgres";
public static readonly string PostgresUser = Environment.GetEnvironmentVariable("POSTGRES_USER") ?? "postgres";
public static readonly string PostgresPassword = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "postgres";
public static readonly int PostgresConnectionTimeout = int.Parse(Environment.GetEnvironmentVariable("POSTGRES_CONNECTION_TIMEOUT") ?? "30");
public static readonly int PostgresCommandTimeout = int.Parse(Environment.GetEnvironmentVariable("POSTGRES_COMMAND_TIMEOUT") ?? "60");
public static readonly bool UpdateChaptersDownloadedBeforeStarting = bool.Parse(Environment.GetEnvironmentVariable("CHECK_CHAPTERS_BEFORE_START") ?? "true");
}

View File

@@ -75,15 +75,15 @@ builder.Services.AddSwaggerGenNewtonsoftSupport().AddSwaggerGen(opt =>
log.Debug("Adding Database-Connection...");
NpgsqlConnectionStringBuilder connectionStringBuilder = new()
{
Host = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "tranga-pg:5432",
Database = Environment.GetEnvironmentVariable("POSTGRES_DB") ?? "postgres",
Username = Environment.GetEnvironmentVariable("POSTGRES_USER") ?? "postgres",
Password = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "postgres",
Host = Constants.PostgresHost,
Database = Constants.PostgresDb,
Username = Constants.PostgresUser,
Password = Constants.PostgresPassword,
ConnectionLifetime = 300,
Timeout = int.Parse(Environment.GetEnvironmentVariable("POSTGRES_CONNECTION_TIMEOUT") ?? "30"),
Timeout = Constants.PostgresConnectionTimeout,
ReadBufferSize = 65536,
WriteBufferSize = 65536,
CommandTimeout = int.Parse(Environment.GetEnvironmentVariable("POSTGRES_COMMAND_TIMEOUT") ?? "60"),
CommandTimeout = Constants.PostgresCommandTimeout,
ApplicationName = "Tranga"
};

View File

@@ -39,8 +39,11 @@ public static class Tranga
{
AddWorker(SendNotificationsWorker);
AddWorker(CleanupMangaconnectorIdsWithoutConnector);
AddWorker(UpdateChaptersDownloadedWorker);
AddWorker(CleanupMangaCoversWorker);
if(Constants.UpdateChaptersDownloadedBeforeStarting)
AddWorker(UpdateChaptersDownloadedWorker);
Log.Info("Waiting for startup to complete...");
while (new List<BaseWorker>() { CleanupMangaconnectorIdsWithoutConnector, UpdateChaptersDownloadedWorker, CleanupMangaCoversWorker}.Any(w => w.State < WorkerExecutionState.Completed))
Thread.Sleep(100);
@@ -54,6 +57,9 @@ public static class Tranga
AddWorker(StartNewChapterDownloadsWorker);
AddWorker(RemoveOldNotificationsWorker);
AddWorker(UpdateCoversWorker);
if(!Constants.UpdateChaptersDownloadedBeforeStarting)
AddWorker(UpdateChaptersDownloadedWorker);
}
internal static bool TryGetMangaConnector(string name, [NotNullWhen(true)]out MangaConnector? mangaConnector)

View File

@@ -10,7 +10,7 @@ public class UpdateChaptersDownloadedWorker(TimeSpan? interval = null, IEnumerab
: BaseWorkerWithContext<MangaContext>(dependsOn), IPeriodic
{
public DateTime LastExecution { get; set; } = DateTime.UnixEpoch;
public TimeSpan Interval { get; set; } = interval??TimeSpan.FromMinutes(60);
public TimeSpan Interval { get; set; } = interval??TimeSpan.FromDays(1);
protected override async Task<BaseWorker[]> DoWorkInternal()
{
Log.Debug("Checking chapter files...");

View File

@@ -138,6 +138,7 @@ The file also includes [tranga-website](https://github.com/C9Glax/tranga-website
| FLARESOLVERR_URL | <empty> |
| POSTGRES_COMMAND_TIMEOUT | [`60`](https://www.npgsql.org/doc/connection-string-parameters.html?q=Command%20Timeout) |
| POSTGRES_CONNECTION_TIMEOUT | `30` |
| CHECK_CHAPTERS_BEFORE_START | `true` |
For compatibility do not execute the compose as root (which you should not do anyways...) but as user that can
access the folder. Permission conflicts with Komga and Kavita should thus be limited.