Skip to content

Commit 150d68d

Browse files
committed
Finish initial lifecycle action implementation
1 parent 79b1aaf commit 150d68d

File tree

3 files changed

+35
-47
lines changed

3 files changed

+35
-47
lines changed

src/InEngine.Core/Queuing/Jobs.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@ private void ScheduleQueueConsumerJobs(Schedule schedule, int consumers, bool us
2020
throw new ArgumentOutOfRangeException(nameof(consumers), consumers, "The number of queue consumers must be 0 or greater.");
2121

2222
foreach (var index in Enumerable.Range(0, consumers).ToList())
23-
schedule.Job(new Consume()
24-
{
23+
schedule.Job(new Consume() {
2524
ScheduleId = $"{(useSecondaryQueue ? "secondary" : "primary")}:{index.ToString()}",
2625
UseSecondaryQueue = useSecondaryQueue
2726
})
28-
.EverySecond();
29-
//.Before(x => Console.Write("Before..."))
30-
//.After(x => Console.Write("After..."));
27+
.EverySecond();
3128
}
3229
}
3330
}

src/InEngine.Core/Scheduling/LifecycleActionApi.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using Quartz;
3-
using Quartz.Impl;
43

54
namespace InEngine.Core.Scheduling
65
{
@@ -19,78 +18,80 @@ public static TriggerBuilder MakeTriggerBuilder(AbstractCommand command)
1918
.WithIdentity($"{command.Name}:job:{command.ScheduleId}", command.SchedulerGroup);
2019
}
2120

22-
public void RegisterJob(Action<DailyTimeIntervalScheduleBuilder> action)
21+
public LifecycleActions RegisterJob(Action<DailyTimeIntervalScheduleBuilder> action)
2322
{
24-
Schedule.RegisterJob(Command, JobDetail, MakeTriggerBuilder(Command).WithDailyTimeIntervalSchedule(action).Build());
23+
return new LifecycleActions {
24+
JobRegistration = Schedule.RegisterJob(Command, JobDetail, MakeTriggerBuilder(Command).WithDailyTimeIntervalSchedule(action).Build())
25+
};
2526
}
2627

27-
public void RegisterJob(string cronExpression)
28+
public LifecycleActions RegisterJob(string cronExpression)
2829
{
29-
Schedule.RegisterJob(Command, JobDetail, MakeTriggerBuilder(Command).WithCronSchedule(cronExpression).Build());
30+
return new LifecycleActions {
31+
JobRegistration = Schedule.RegisterJob(Command, JobDetail, MakeTriggerBuilder(Command).WithCronSchedule(cronExpression).Build())
32+
};
3033
}
3134

32-
public void RegisterJob(Action<SimpleScheduleBuilder> action)
35+
public LifecycleActions RegisterJob(Action<SimpleScheduleBuilder> action)
3336
{
34-
Schedule.RegisterJob(Command, JobDetail, MakeTriggerBuilder(Command).WithSimpleSchedule(action).Build());
37+
return new LifecycleActions {
38+
JobRegistration = Schedule.RegisterJob(Command, JobDetail, MakeTriggerBuilder(Command).WithSimpleSchedule(action).Build())
39+
};
3540
}
3641

37-
public void Cron(string cronExpression)
42+
public LifecycleActions Cron(string cronExpression)
3843
{
39-
RegisterJob(cronExpression);
44+
return RegisterJob(cronExpression);
4045
}
4146

4247
public LifecycleActions EverySecond()
4348
{
44-
RegisterJob(x => x.WithIntervalInSeconds(1).RepeatForever());
45-
return new LifecycleActions()
46-
{
47-
Command = Command
48-
};
49+
return RegisterJob(x => x.WithIntervalInSeconds(1).RepeatForever());
4950
}
5051

51-
public void EveryMinute()
52+
public LifecycleActions EveryMinute()
5253
{
53-
RegisterJob(x => x.WithIntervalInMinutes(1).RepeatForever());
54+
return RegisterJob(x => x.WithIntervalInMinutes(1).RepeatForever());
5455
}
5556

56-
public void EveryFiveMinutes()
57+
public LifecycleActions EveryFiveMinutes()
5758
{
58-
RegisterJob(x => x.WithIntervalInMinutes(5).RepeatForever());
59+
return RegisterJob(x => x.WithIntervalInMinutes(5).RepeatForever());
5960
}
6061

61-
public void EveryTenMinutes()
62+
public LifecycleActions EveryTenMinutes()
6263
{
63-
RegisterJob(x => x.WithIntervalInMinutes(10).RepeatForever());
64+
return RegisterJob(x => x.WithIntervalInMinutes(10).RepeatForever());
6465
}
6566

66-
public void EveryFifteenMinutes()
67+
public LifecycleActions EveryFifteenMinutes()
6768
{
68-
RegisterJob(x => x.WithIntervalInMinutes(15).RepeatForever());
69+
return RegisterJob(x => x.WithIntervalInMinutes(15).RepeatForever());
6970
}
7071

71-
public void EveryThirtyMinutes()
72+
public LifecycleActions EveryThirtyMinutes()
7273
{
73-
RegisterJob(x => x.WithIntervalInMinutes(30).RepeatForever());
74+
return RegisterJob(x => x.WithIntervalInMinutes(30).RepeatForever());
7475
}
7576

76-
public void Hourly()
77+
public LifecycleActions Hourly()
7778
{
78-
RegisterJob(x => x.WithIntervalInHours(1).RepeatForever());
79+
return RegisterJob(x => x.WithIntervalInHours(1).RepeatForever());
7980
}
8081

81-
public void HourlyAt(int minutesAfterTheHour)
82+
public LifecycleActions HourlyAt(int minutesAfterTheHour)
8283
{
83-
RegisterJob($"0 {minutesAfterTheHour} * * * ?");
84+
return RegisterJob($"0 {minutesAfterTheHour} * * * ?");
8485
}
8586

86-
public void Daily()
87+
public LifecycleActions Daily()
8788
{
88-
RegisterJob(x => x.WithIntervalInHours(24).RepeatForever());
89+
return RegisterJob(x => x.WithIntervalInHours(24).RepeatForever());
8990
}
9091

91-
public void DailyAt(int hours, int minutes, int seconds = 0)
92+
public LifecycleActions DailyAt(int hours, int minutes, int seconds = 0)
9293
{
93-
RegisterJob(x => x.StartingDailyAt(new TimeOfDay(hours, minutes, seconds)));
94+
return RegisterJob(x => x.StartingDailyAt(new TimeOfDay(hours, minutes, seconds)));
9495
}
9596
}
9697
}

0 commit comments

Comments
 (0)