Skip to content

Commit

Permalink
Merge pull request #457 from classtranscribe/LimitSlowPathToRecentItems
Browse files Browse the repository at this point in the history
Limit slow path to recent items
  • Loading branch information
angrave authored Jan 26, 2024
2 parents fa176f2 + d68e773 commit 9b6a89f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 14 additions & 1 deletion TaskEngine/Tasks/DownloadPlaylistInfoTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ protected override async Task OnConsume(string playlistId, TaskParameters taskPa
RegisterTask(cleanup, playlistId); // may throw AlreadyInProgress exception
using (var _context = CTDbContext.CreateDbContext())
{
var playlist = await _context.Playlists.FindAsync(playlistId);

var playlist = await _context.Playlists.Include(p=>p.Offering).Where(p=> p.Id == playlistId).FirstOrDefaultAsync();
if (playlist == null)
{
GetLogger().LogError($"Playlist {playlistId} not found");
return;
}
if(playlist.Offering == null || playlist.Offering.CourseName == null)
{
GetLogger().LogError($"Playlist {playlistId} has no associated offering ");
return;
}
GetLogger().LogInformation($"Playlist {playlistId}:<{playlist.Name}>/{playlist.Offering.CourseName}: type=({playlist.SourceType}) unique=({playlist.PlaylistIdentifier})");
int index = 0;
try {
index = 1 + await _context.Medias.Where(m=> m.PlaylistId == playlist.Id).Select(m => m.Index).MaxAsync();
Expand Down Expand Up @@ -82,6 +94,7 @@ protected override async Task OnConsume(string playlistId, TaskParameters taskPa
playlist.ListUpdatedAt = playlist.ListCheckedAt;
}
await _context.SaveChangesAsync();
GetLogger().LogInformation($"Playlist {playlistId}: Task Complete");

}
}
Expand Down
5 changes: 3 additions & 2 deletions TaskEngine/Tasks/QueueAwakerTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,19 @@ private async Task PendingJobs()
// todoVTTs = await context.Transcriptions.AsNoTracking().Where(
// t => t.Captions.Count > 0 && t.File == null && t.CreatedAt < tooRecentCutoff
// ).OrderByDescending(t => t.CreatedAt).Take(maxVTTs).Select(e => e.Id).ToListAsync();
var last3Months = DateTime.Now.AddMonths(-3);

var maxSceneDetection = 400;
todoSceneDetection = await context.Videos.AsNoTracking().Where(
v=> (v.PhraseHintsDataId== null) && v.PhraseHints == null &&
v.Medias.Any() && v.CreatedAt < tooRecentCutoff
v.Medias.Any() && v.CreatedAt < tooRecentCutoff && v.CreatedAt > last3Months
).OrderByDescending(t => t.CreatedAt).Take(maxSceneDetection).Select(e => e.Id).ToListAsync();

var maxTranscriptions = 40;
todoTranscriptions = await context.Videos.AsNoTracking().Where(
v=> (v.PhraseHintsDataId != null || v.PhraseHints != null) &&
v.TranscribingAttempts < 41 && v.TranscriptionStatus != "NoError" &&
v.Medias.Any() && v.CreatedAt < tooRecentCutoff
v.Medias.Any() && v.CreatedAt < tooRecentCutoff && v.CreatedAt > last3Months
).OrderByDescending(t => t.CreatedAt).Take(maxTranscriptions).Select(e => e.Id).ToListAsync();

// Medias for which no videos have downloaded
Expand Down

0 comments on commit 9b6a89f

Please sign in to comment.