Skip to content

Commit f3f1e77

Browse files
committed
Allow lambdas to be scheduled
1 parent 23759ec commit f3f1e77

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

src/InEngine.Core.Test/InEngine.Core.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@
2828
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2929
</None>
3030
</ItemGroup>
31+
<ItemGroup>
32+
<Folder Include="Scheduling\" />
33+
</ItemGroup>
3134
</Project>
3235

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using BeekmanLabs.UnitTesting;
3+
using InEngine.Commands;
4+
using InEngine.Core.Commands;
5+
using InEngine.Core.Scheduling;
6+
using Moq;
7+
using NUnit.Framework;
8+
using Quartz;
9+
10+
namespace InEngine.Core.Test.Scheduling
11+
{
12+
[TestFixture]
13+
public class ScheduleTest : TestBase<Schedule>
14+
{
15+
[SetUp]
16+
public void Setup()
17+
{
18+
InEngineSettings.BasePath = TestContext.CurrentContext.TestDirectory;
19+
}
20+
21+
[Test]
22+
public void ShouldScheduleToRunCommandEverySecond()
23+
{
24+
var alwaysSucceed = new AlwaysSucceed();
25+
26+
Subject.Job(alwaysSucceed).EverySecond();
27+
}
28+
29+
[Test]
30+
public void ShouldScheduleToRunLambdaEverySecond()
31+
{
32+
var alwaysSucceed = new AlwaysSucceed();
33+
34+
Subject.Job(() => { Console.WriteLine("Hello, world!"); }).EverySecond();
35+
}
36+
}
37+
}

src/InEngine.Core.Test/appsettings.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
"PrimaryQueueConsumers": 16,
99
"SecondaryQueueConsumers": 4,
1010
"QueueDriver": "file",
11-
"QueueName": "InEngineQueue",
12-
"RedisHost": "localhost",
13-
"RedisPort": 6379,
14-
"RedisDb": 0,
15-
"RedisPassword": ""
11+
"QueueName": "InEngineQueue"
1612
}
1713
}
1814
}

src/InEngine.Core/Scheduling/Schedule.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using InEngine.Core.Commands;
45
using InEngine.Core.Exceptions;
56
using Quartz;
67
using Quartz.Impl;
@@ -31,6 +32,11 @@ public Occurence Job(AbstractCommand command)
3132
};
3233
}
3334

35+
public Occurence Job(Action action)
36+
{
37+
return Job(new Lambda() { Action = action });
38+
}
39+
3440
public JobRegistration RegisterJob(AbstractCommand command, IJobDetail jobDetail, ITrigger trigger)
3541
{
3642
if (!JobGroups.ContainsKey(command.SchedulerGroup))

0 commit comments

Comments
 (0)