[backend/core] Fix queue system logging rendering UTC timestamps & reporting of incorrect duration for delayed jobs due to time zone differences

This commit is contained in:
Laura Hausmann 2024-03-26 12:06:12 +01:00
parent 7eba307d0a
commit 5556832de0
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 4 additions and 4 deletions

View file

@ -34,7 +34,7 @@ public class Job
[Column("data")] public string Data { get; set; } = null!;
[NotMapped]
public long Duration => (long)((FinishedAt ?? DateTime.Now) - (StartedAt ?? QueuedAt)).TotalMilliseconds;
public long Duration => (long)((FinishedAt ?? DateTime.UtcNow) - (StartedAt ?? QueuedAt)).TotalMilliseconds;
[NotMapped] public long QueueDuration => (long)((StartedAt ?? DateTime.Now) - QueuedAt).TotalMilliseconds;
[NotMapped] public long QueueDuration => (long)((StartedAt ?? DateTime.UtcNow) - QueuedAt).TotalMilliseconds;
}

View file

@ -348,8 +348,8 @@ public class PostgresJobQueue<T>(
{
var logger = scope.ServiceProvider.GetRequiredService<ILogger<QueueService>>();
logger.LogTrace("Job in queue {queue} was delayed to {time} after {duration} ms, has been queued since {time}",
name, job.DelayedUntil.Value.ToStringIso8601Like(), job.Duration,
job.QueuedAt.ToStringIso8601Like());
name, job.DelayedUntil.Value.ToLocalTime().ToStringIso8601Like(), job.Duration,
job.QueuedAt.ToLocalTime().ToStringIso8601Like());
db.Update(job);
await db.SaveChangesAsync(token);
await RaiseJobDelayedEvent(db);