Skip to content

Commit

Permalink
refactor: fix DeepSource advices again
Browse files Browse the repository at this point in the history
Signed-off-by: 陳鈞 <[email protected]>
  • Loading branch information
jim60105 committed Mar 6, 2024
1 parent 2a8e057 commit 4ef7ae5
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 25 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/AddKubernetesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static IServiceCollection AddKubernetesService(this IServiceCollection se
.ValidateOnStart();

KubernetesClientConfiguration k8sConfig =
// skipcq: CS-R1114
kubernetesOptions.UseTheSameCluster
? KubernetesClientConfiguration.InClusterConfig()
: !string.IsNullOrWhiteSpace(kubernetesOptions.ConfigFile)
Expand Down
4 changes: 2 additions & 2 deletions Helper/NameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static string GetFileName(Video video, string Platform)
{
"Youtube" or IYtarchiveService.name or IYtdlpService.name => $"{video.id}.mp4",
"Twitch" or IStreamlinkService.name => $"{video.id}.mp4",
"Twitcasting" or ITwitcastingRecorderService.name => $"{video.ChannelId}_{DateTime.Now:yyyyMMddHHmmss}.mp4",
"FC2" or IFC2LiveDLService.name => $"{video.ChannelId}_{DateTime.Now:yyyyMMddHHmmss}.mp4",
"Twitcasting" or ITwitcastingRecorderService.name => $"{video.ChannelId}_{DateTime.UtcNow:yyyyMMddHHmmss}.mp4",
"FC2" or IFC2LiveDLService.name => $"{video.ChannelId}_{DateTime.UtcNow:yyyyMMddHHmmss}.mp4",
_ => throw new NotImplementedException(),
};

Expand Down
1 change: 1 addition & 0 deletions Helper/YoutubeDLHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static async Task<RunResult<YtdlpVideoData>> RunVideoDataFetch_Alt(this Y
optionSet = optionSet.OverrideOptions(overrideOptions);
}

// skipcq: CS-W1028
YtdlpVideoData videoData = null;
YoutubeDLProcess youtubeDLProcess = new(ytdl.YoutubeDLPath);
youtubeDLProcess.OutputReceived += (o, e) =>
Expand Down
4 changes: 2 additions & 2 deletions ScopedServices/PlatformService/FC2Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ await fC2LiveDLService.InitJobAsync(url: $"https://live.fc2.com/{NameHelper.Chan
}));
if (null != discordService)
{
await discordService.SendStartRecordingMessage(video, channel);
await discordService.SendStartRecordingMessageAsync(video, channel);
}
}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
if (video.Status >= VideoStatus.Archived && video.Status < VideoStatus.Expired)
{
video.Status = VideoStatus.Missing;
video.Note = $"Video missing because archived not found.";
video.Note = "Video missing because archived not found.";
logger.LogInformation("Can not found archived, change video status to {status}", Enum.GetName(typeof(VideoStatus), video.Status));
}
}
Expand Down
6 changes: 3 additions & 3 deletions ScopedServices/PlatformService/TwitcastingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ await twitcastingRecorderService.InitJobAsync(url: videoId,

if (null != discordService)
{
await discordService.SendStartRecordingMessage(video, channel);
await discordService.SendStartRecordingMessageAsync(video, channel);
}
}
}
Expand Down Expand Up @@ -293,7 +293,7 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
if (video.SourceStatus != VideoStatus.Reject)
{
video.SourceStatus = VideoStatus.Reject;
video.Note = $"Video source is detected access required.";
video.Note = "Video source is detected access required.";
if (null != discordService)
{
await discordService.SendDeletedMessageAsync(video, channel);
Expand Down Expand Up @@ -338,7 +338,7 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
if (video.Status >= VideoStatus.Archived && video.Status < VideoStatus.Expired)
{
video.Status = VideoStatus.Missing;
video.Note = $"Video missing because archived not found.";
video.Note = "Video missing because archived not found.";
logger.LogInformation("Can not found archived, change video status to {status}", Enum.GetName(typeof(VideoStatus), video.Status));
}
}
Expand Down
2 changes: 1 addition & 1 deletion ScopedServices/PlatformService/TwitchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ await streamlinkService.InitJobAsync(url: video.id,
logger.LogInformation("{channelId} is now lived! Start recording.", channel.id);
if (null != discordService)
{
await discordService.SendStartRecordingMessage(video, channel);
await discordService.SendStartRecordingMessageAsync(video, channel);
}
}

Expand Down
10 changes: 5 additions & 5 deletions ScopedServices/PlatformService/YoutubeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
if (video.Status != VideoStatus.Skipped
&& null != discordService)
{
await discordService.SendSkippedMessage(video, channel);
await discordService.SendSkippedMessageAsync(video, channel);
}
video.Status = VideoStatus.Skipped;
logger.LogInformation("Change video {videoId} status to {videoStatus}", video.id, Enum.GetName(typeof(VideoStatus), video.Status));
Expand Down Expand Up @@ -264,7 +264,7 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
if (video.Status != VideoStatus.Skipped
&& null != discordService)
{
await discordService.SendSkippedMessage(video, channel);
await discordService.SendSkippedMessageAsync(video, channel);
}
video.Status = VideoStatus.Skipped;
logger.LogInformation("Change video {videoId} status to {videoStatus}", video.id, Enum.GetName(typeof(VideoStatus), video.Status));
Expand Down Expand Up @@ -356,7 +356,7 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
video.SourceStatus = VideoStatus.Missing;
if (null != discordService)
{
await discordService.SendSkippedMessage(video, channel);
await discordService.SendSkippedMessageAsync(video, channel);
}
}
video.Status = VideoStatus.Missing;
Expand Down Expand Up @@ -426,7 +426,7 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
if (video.Status != VideoStatus.Skipped
&& null != discordService)
{
await discordService.SendSkippedMessage(video, channel);
await discordService.SendSkippedMessageAsync(video, channel);
}
video.Status = VideoStatus.Skipped;
logger.LogInformation("Video is {status} because it is detected access required or copyright notice.", Enum.GetName(typeof(VideoStatus), video.Status));
Expand Down Expand Up @@ -461,7 +461,7 @@ await ytarchiveService.InitJobAsync(url: video.id,
logger.LogInformation("{videoId} is now lived! Start recording.", video.id);
if (null != discordService)
{
await discordService.SendStartRecordingMessage(video, channel);
await discordService.SendStartRecordingMessageAsync(video, channel);
}
}

Expand Down
9 changes: 5 additions & 4 deletions SingletonServices/DiscordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public DiscordService(
/// </summary>
/// <param name="arg"></param>
/// <returns></returns>
// skipcq: CS-R1073
private Task DiscordWebhookClient_Log(LogMessage arg)
=> Task.Run(() =>
{
Expand All @@ -70,15 +71,15 @@ private Task DiscordWebhookClient_Log(LogMessage arg)
case LogSeverity.Verbose:
_logger.LogTrace("{message}", arg);
break;
case LogSeverity.Debug:
// case LogSeverity.Debug:
default:
_logger.LogDebug("{message}", arg);
break;
}
});
#endregion

public Task SendStartRecordingMessage(Video video, Channel? channel)
public Task SendStartRecordingMessageAsync(Video video, Channel? channel)
{
var embedBuilder = GetEmbedBuilder(video, channel);
embedBuilder.WithTitle("Start Recording");
Expand All @@ -89,7 +90,7 @@ public Task SendStartRecordingMessage(Video video, Channel? channel)
return SendMessageAsync(embedBuilder.Build(), componentBuilder.Build());
}

public Task SendArchivedMessage(Video video, Channel? channel)
public Task SendArchivedMessageAsync(Video video, Channel? channel)
{
var embedBuilder = GetEmbedBuilder(video, channel);
embedBuilder.WithTitle("Video archived");
Expand All @@ -100,7 +101,7 @@ public Task SendArchivedMessage(Video video, Channel? channel)
return SendMessageAsync(embedBuilder.Build(), componentBuilder.Build());
}

public Task SendSkippedMessage(Video video, Channel? channel)
public Task SendSkippedMessageAsync(Video video, Channel? channel)
{
var embedBuilder = GetEmbedBuilder(video, channel);
embedBuilder.WithTitle("Video skipped");
Expand Down
4 changes: 2 additions & 2 deletions SingletonServices/RecordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task HandledFailedJobsAsync(VideoService videoService, Cancellation
// Only check videos that started recording/download more than 3 minutes ago
// to avoid checking videos that are not finished deployment yet.
.Where(p => null != p.Timestamps.ActualStartTime
&& DateTime.Now.Subtract(p.Timestamps.ActualStartTime.Value).TotalMinutes >= 3)
&& DateTime.UtcNow.Subtract(p.Timestamps.ActualStartTime.Value).TotalMinutes >= 3)
.ToList();

if (videos.Count > 0)
Expand Down Expand Up @@ -296,7 +296,7 @@ public async Task ProcessUploadedVideoAsync(VideoService videoService, ChannelSe
{
using var _ = LogContext.PushProperty("videoId", video.id);

await discordService.SendArchivedMessage(video, await channelService.GetByChannelIdAndSourceAsync(video.ChannelId, video.Source));
await discordService.SendArchivedMessageAsync(video, await channelService.GetByChannelIdAndSourceAsync(video.ChannelId, video.Source));
logger.LogInformation("Video {videoId} is successfully uploaded to Storage.", video.id);
await videoService.UpdateVideoStatusAsync(video, VideoStatus.Archived);

Expand Down
2 changes: 1 addition & 1 deletion Workers/HeartbeatWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

while (!stoppingToken.IsCancellationRequested)
{
using var __ = LogContext.PushProperty("WorkerRunId", $"{nameof(HeartbeatWorker)}_{DateTime.Now:yyyyMMddHHmmssfff}");
using var __ = LogContext.PushProperty("WorkerRunId", $"{nameof(HeartbeatWorker)}_{DateTime.UtcNow:yyyyMMddHHmmssfff}");

await SendHeartbeatAsync();

Expand Down
2 changes: 1 addition & 1 deletion Workers/MonitorWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

while (!stoppingToken.IsCancellationRequested)
{
using var __ = LogContext.PushProperty("WorkerRunId", $"{nameof(MonitorWorker)}_{DateTime.Now:yyyyMMddHHmmssfff}");
using var __ = LogContext.PushProperty("WorkerRunId", $"{nameof(MonitorWorker)}_{DateTime.UtcNow:yyyyMMddHHmmssfff}");

#region DI
using (var scope = serviceProvider.CreateScope())
Expand Down
2 changes: 1 addition & 1 deletion Workers/RecordWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
logger.LogTrace("{Worker} starts...", nameof(RecordWorker));
while (!stoppingToken.IsCancellationRequested)
{
using var ____ = LogContext.PushProperty("WorkerRunId", $"{nameof(RecordWorker)}_{DateTime.Now:yyyyMMddHHmmssfff}");
using var ____ = LogContext.PushProperty("WorkerRunId", $"{nameof(RecordWorker)}_{DateTime.UtcNow:yyyyMMddHHmmssfff}");
#region DI
using (var scope = serviceProvider.CreateScope())
{
Expand Down
2 changes: 1 addition & 1 deletion Workers/UpdateChannelInfoWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

while (!stoppingToken.IsCancellationRequested)
{
using var __ = LogContext.PushProperty("WorkerRunId", $"{nameof(UpdateChannelInfoWorker)}_{DateTime.Now:yyyyMMddHHmmssfff}");
using var __ = LogContext.PushProperty("WorkerRunId", $"{nameof(UpdateChannelInfoWorker)}_{DateTime.UtcNow:yyyyMMddHHmmssfff}");

#region DI
using var scope = serviceProvider.CreateScope();
Expand Down
4 changes: 2 additions & 2 deletions Workers/UpdateVideoStatusWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
var expireDate = DateTime.Today;
while (!stoppingToken.IsCancellationRequested)
{
using var __ = LogContext.PushProperty("WorkerRunId", $"{nameof(UpdateVideoStatusWorker)}_{DateTime.Now:yyyyMMddHHmmssfff}");
using var __ = LogContext.PushProperty("WorkerRunId", $"{nameof(UpdateVideoStatusWorker)}_{DateTime.UtcNow:yyyyMMddHHmmssfff}");

#region DI
using (var scope = serviceProvider.CreateScope())
Expand Down Expand Up @@ -71,7 +71,7 @@ .. videoRepository.Where(p => p.Status >= VideoStatus.Archived
}

// Expire videos once a day
if (DateTime.Now > expireDate)
if (DateTime.UtcNow > expireDate)
{
expireDate = expireDate.AddDays(1);
await ExpireVideosAsync(videoService, stoppingToken);
Expand Down

0 comments on commit 4ef7ae5

Please sign in to comment.