Skip to content

Commit

Permalink
using concurrent dictionary in Dispatcher rather than hashset which w…
Browse files Browse the repository at this point in the history
…as throwing errors because it's not thread safe

audit now showing hours
now calling AfterDom() for right sided overlays
  • Loading branch information
yohsii committed Dec 20, 2019
1 parent 318fcbf commit 8fa40b3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions core/Concrete/Dispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
using puck.core.State;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Concurrent;

namespace puck.core.Concrete
{
public class Dispatcher:I_Task_Dispatcher,IHostedService,IDisposable
{
public Dispatcher() {
this.QueuedTasks = new HashSet<int>();
this.QueuedTasks = new ConcurrentDictionary<int, int>();
CatchUp=PuckCache.TaskCatchUp;
}
private HashSet<int> QueuedTasks { get; set; }
private ConcurrentDictionary<int,int> QueuedTasks { get; set; }
System.Timers.Timer tmr;
private static object lck= new object();
int lock_wait = 100;
Expand Down Expand Up @@ -51,7 +52,8 @@ public void OnTaskEnd(BaseTask t){

}
public void HandleTaskEnd(object s, DispatchEventArgs e){
QueuedTasks.Remove(e.Task.ID);
int removedId=0;
QueuedTasks.Remove(e.Task.ID,out removedId);
if (!e.Task.Recurring)
{
Tasks.Remove(e.Task);
Expand Down Expand Up @@ -82,9 +84,9 @@ public void Dispatch(object sender, EventArgs e) {
return;

foreach (var t in Tasks) {
if (ShouldRunNow(t)&&!QueuedTasks.Contains(t.ID))
if (ShouldRunNow(t)&&!QueuedTasks.ContainsKey(t.ID))
{
QueuedTasks.Add(t.ID);
QueuedTasks.TryAdd(t.ID,t.ID);
System.Threading.Tasks.Task.Factory.StartNew(() => {
t.DoRun(this.cancellationToken);
}, cancellationToken);
Expand Down
1 change: 1 addition & 0 deletions core/core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.0-rc1.final" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
<PackageReference Include="SixLabors.ImageSharp.Web" Version="1.0.0-beta0009" />
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion puckweb/Areas/puck/Views/Api/Audit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
@Html.DisplayFor(modelItem => item.Username)
</td>
<td>
@item.Timestamp.ToString("dd/MM/yyyy mm:ss")
@item.Timestamp.ToString("dd/MM/yyyy HH:mm:ss")
</td>
<td>
@Html.DisplayFor(modelItem => item.Notes)
Expand Down
1 change: 1 addition & 0 deletions puckweb/wwwroot/Areas/puck/assets/js/puck.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ var overlay = function (el, width, height, top, title, isRightSided) {
cright.append(outer);
if (!isRightSided)
outer.animate({ width: width + (width.toString().indexOf("%") > -1 ? "" : "px") }, 200, function () { if (f) f(); afterDom(); });
else afterDom();
if ($(".overlay_screen.active").length == 1) {
$(document).off("keyup.overlay").on("keyup.overlay", function (e) {
if (e.keyCode == 27) { overlayClose(cleftIsVisible, overlayClass); }
Expand Down

0 comments on commit 8fa40b3

Please # to comment.