Skip to content

Commit

Permalink
improved group completed callback
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanfuchs committed Sep 22, 2024
1 parent 0ad250f commit 842b414
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Lingarr.Client/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ onMounted(async () => {
})
onUnmounted(() => {
signalR.off('GroupCompleted', () => null)
signalR.off('GroupCompleted', () => {})
})
</script>
1 change: 1 addition & 0 deletions Lingarr.Client/src/components/layout/ContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function toggle() {
function selectOption(option: ILanguage) {
translateStore.translateSubtitle(subtitle, option)
toggle()
tooltip.value?.showTooltip()
}
Expand Down
16 changes: 11 additions & 5 deletions Lingarr.Server/Hubs/ScheduleProgressHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Lingarr.Server.Models;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Hangfire;

namespace Lingarr.Server.Hubs;

Expand All @@ -23,7 +24,7 @@ public async Task JoinGroup(GroupRequest request)
var translationJob = await _dbContext.TranslationJobs
.FirstOrDefaultAsync(translationJob => translationJob.JobId == group);

if (translationJob == null)
if (translationJob == null && CheckIfJobExists(request.Group))
{
translationJob = new TranslationJob
{
Expand All @@ -32,10 +33,6 @@ public async Task JoinGroup(GroupRequest request)
};
_dbContext.TranslationJobs.Add(translationJob);
await _dbContext.SaveChangesAsync();
}

if (!translationJob.Completed)
{
await Groups.AddToGroupAsync(Context.ConnectionId, group);
await Clients.Caller.SendAsync("JoinedGroup", group);
}
Expand All @@ -50,4 +47,13 @@ public async Task LeaveGroup(GroupRequest request)
string group = request.Group;
await Groups.RemoveFromGroupAsync(Context.ConnectionId, group);
}

private bool CheckIfJobExists(string jobId)
{
using (var connection = JobStorage.Current.GetConnection())
{
var job = connection.GetJobData(jobId);
return job != null;
}
}
}

0 comments on commit 842b414

Please sign in to comment.