Skip to content

Commit 8fa40b3

Browse files
committedDec 20, 2019
using concurrent dictionary in Dispatcher rather than hashset which was throwing errors because it's not thread safe
audit now showing hours now calling AfterDom() for right sided overlays
1 parent 318fcbf commit 8fa40b3

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed
 

‎core/Concrete/Dispatcher.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
using puck.core.State;
1515
using Microsoft.Extensions.Hosting;
1616
using Microsoft.Extensions.DependencyInjection;
17+
using System.Collections.Concurrent;
1718

1819
namespace puck.core.Concrete
1920
{
2021
public class Dispatcher:I_Task_Dispatcher,IHostedService,IDisposable
2122
{
2223
public Dispatcher() {
23-
this.QueuedTasks = new HashSet<int>();
24+
this.QueuedTasks = new ConcurrentDictionary<int, int>();
2425
CatchUp=PuckCache.TaskCatchUp;
2526
}
26-
private HashSet<int> QueuedTasks { get; set; }
27+
private ConcurrentDictionary<int,int> QueuedTasks { get; set; }
2728
System.Timers.Timer tmr;
2829
private static object lck= new object();
2930
int lock_wait = 100;
@@ -51,7 +52,8 @@ public void OnTaskEnd(BaseTask t){
5152

5253
}
5354
public void HandleTaskEnd(object s, DispatchEventArgs e){
54-
QueuedTasks.Remove(e.Task.ID);
55+
int removedId=0;
56+
QueuedTasks.Remove(e.Task.ID,out removedId);
5557
if (!e.Task.Recurring)
5658
{
5759
Tasks.Remove(e.Task);
@@ -82,9 +84,9 @@ public void Dispatch(object sender, EventArgs e) {
8284
return;
8385

8486
foreach (var t in Tasks) {
85-
if (ShouldRunNow(t)&&!QueuedTasks.Contains(t.ID))
87+
if (ShouldRunNow(t)&&!QueuedTasks.ContainsKey(t.ID))
8688
{
87-
QueuedTasks.Add(t.ID);
89+
QueuedTasks.TryAdd(t.ID,t.ID);
8890
System.Threading.Tasks.Task.Factory.StartNew(() => {
8991
t.DoRun(this.cancellationToken);
9092
}, cancellationToken);

‎core/core.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.0-rc1.final" />
5656
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
5757
<PackageReference Include="SixLabors.ImageSharp.Web" Version="1.0.0-beta0009" />
58+
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
5859
</ItemGroup>
5960

6061
<ItemGroup>

‎puckweb/Areas/puck/Views/Api/Audit.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
@Html.DisplayFor(modelItem => item.Username)
5050
</td>
5151
<td>
52-
@item.Timestamp.ToString("dd/MM/yyyy mm:ss")
52+
@item.Timestamp.ToString("dd/MM/yyyy HH:mm:ss")
5353
</td>
5454
<td>
5555
@Html.DisplayFor(modelItem => item.Notes)

‎puckweb/wwwroot/Areas/puck/assets/js/puck.actions.js

+1
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ var overlay = function (el, width, height, top, title, isRightSided) {
11301130
cright.append(outer);
11311131
if (!isRightSided)
11321132
outer.animate({ width: width + (width.toString().indexOf("%") > -1 ? "" : "px") }, 200, function () { if (f) f(); afterDom(); });
1133+
else afterDom();
11331134
if ($(".overlay_screen.active").length == 1) {
11341135
$(document).off("keyup.overlay").on("keyup.overlay", function (e) {
11351136
if (e.keyCode == 27) { overlayClose(cleftIsVisible, overlayClass); }

0 commit comments

Comments
 (0)