Skip to content

Commit 8f94658

Browse files
committed
Refactor
1 parent bd22e84 commit 8f94658

File tree

3 files changed

+41
-75
lines changed

3 files changed

+41
-75
lines changed

src/InEngine.Commands/CommandsPlugin.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using CommandLine;
43
using InEngine.Core;
54
using InEngine.Core.Commands;
@@ -18,24 +17,24 @@ public class CommandsPlugin : AbstractPlugin
1817
public override void Schedule(ISchedule schedule)
1918
{
2019
schedule.Command(new Echo { VerbatimText = "Core Echo command." })
21-
.EverySecond()
22-
.Before(x => Console.WriteLine("Before"))
23-
.After(x => Console.WriteLine("After"))
24-
.PingBefore("http://www.google.com")
25-
.PingAfter("http://www.google.com")
20+
.EveryMinute()
21+
.Before(x => x.Line($"Before {x.Name}"))
22+
.After(x => x.Line($"After {x.Name}"))
23+
.PingBefore("https://www.google.com")
24+
.PingAfter("https://www.google.com")
2625
.WriteOutputTo("AlwaysSucceedWrite.log")
2726
.AppendOutputTo("AlwaysSucceedAppend.log")
2827
.EmailOutputTo("example@inengine.net");
2928

3029
schedule.Command(new AbstractCommand[] {
3130
new Echo { VerbatimText = "Chain Link 1" },
3231
new Echo { VerbatimText = "Chain Link 2" },
33-
}).EverySecond();
32+
}).EveryFiveMinutes();
3433

3534
schedule.Command(new List<AbstractCommand> {
3635
new Echo { VerbatimText = "Chain Link A" },
3736
new AlwaysFail(),
3837
new Echo { VerbatimText = "Chain Link C" },
39-
}).EverySecond();
38+
}).EveryFifteenMinutes();
4039
}
4140
}

src/InEngine.Core/Scheduling/Occurence.cs

Lines changed: 31 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,85 +13,52 @@ public class Occurence
1313
public static TriggerBuilder MakeTriggerBuilder(AbstractCommand command)
1414
{
1515
if (command == null)
16-
throw new ArgumentNullException(command.GetType().Name, "The command to schedule cannot be null.");
16+
throw new ArgumentNullException(nameof(command), "The command to schedule cannot be null");
1717
return TriggerBuilder
1818
.Create()
1919
.WithIdentity($"{command.Name}:job:{command.ScheduleId}", command.SchedulerGroup);
2020
}
2121

22-
public ScheduleLifeCycleBuilder RegisterJob(Action<DailyTimeIntervalScheduleBuilder> action)
23-
{
24-
return new ScheduleLifeCycleBuilder {
25-
JobRegistration = Schedule.RegisterJob(Command, JobDetail, MakeTriggerBuilder(Command).WithDailyTimeIntervalSchedule(action).Build())
22+
public ScheduleLifeCycleBuilder RegisterJob(Action<DailyTimeIntervalScheduleBuilder> action) =>
23+
new ScheduleLifeCycleBuilder
24+
{
25+
JobRegistration = Schedule.RegisterJob(Command, JobDetail,
26+
MakeTriggerBuilder(Command).WithDailyTimeIntervalSchedule(action).Build())
2627
};
27-
}
2828

29-
public ScheduleLifeCycleBuilder RegisterJob(string cronExpression)
30-
{
31-
return new ScheduleLifeCycleBuilder {
32-
JobRegistration = Schedule.RegisterJob(Command, JobDetail, MakeTriggerBuilder(Command).WithCronSchedule(cronExpression).Build())
29+
public ScheduleLifeCycleBuilder RegisterJob(string cronExpression) =>
30+
new ScheduleLifeCycleBuilder
31+
{
32+
JobRegistration = Schedule.RegisterJob(Command, JobDetail,
33+
MakeTriggerBuilder(Command).WithCronSchedule(cronExpression).Build())
3334
};
34-
}
3535

36-
public ScheduleLifeCycleBuilder RegisterJob(Action<SimpleScheduleBuilder> action)
37-
{
38-
return new ScheduleLifeCycleBuilder {
39-
JobRegistration = Schedule.RegisterJob(Command, JobDetail, MakeTriggerBuilder(Command).WithSimpleSchedule(action).Build())
36+
public ScheduleLifeCycleBuilder RegisterJob(Action<SimpleScheduleBuilder> action) =>
37+
new ScheduleLifeCycleBuilder
38+
{
39+
JobRegistration = Schedule.RegisterJob(Command, JobDetail,
40+
MakeTriggerBuilder(Command).WithSimpleSchedule(action).Build())
4041
};
41-
}
42-
43-
public ScheduleLifeCycleBuilder Cron(string cronExpression)
44-
{
45-
return RegisterJob(cronExpression);
46-
}
47-
48-
public ScheduleLifeCycleBuilder EverySecond()
49-
{
50-
return RegisterJob(x => x.WithIntervalInSeconds(1).RepeatForever());
51-
}
52-
53-
public ScheduleLifeCycleBuilder EveryMinute()
54-
{
55-
return RegisterJob(x => x.WithIntervalInMinutes(1).RepeatForever());
56-
}
57-
58-
public ScheduleLifeCycleBuilder EveryFiveMinutes()
59-
{
60-
return RegisterJob(x => x.WithIntervalInMinutes(5).RepeatForever());
61-
}
6242

63-
public ScheduleLifeCycleBuilder EveryTenMinutes()
64-
{
65-
return RegisterJob(x => x.WithIntervalInMinutes(10).RepeatForever());
66-
}
43+
public ScheduleLifeCycleBuilder Cron(string cronExpression) => RegisterJob(cronExpression);
44+
public ScheduleLifeCycleBuilder EverySecond() => RegisterJob(x => x.WithIntervalInSeconds(1).RepeatForever());
45+
public ScheduleLifeCycleBuilder EveryMinute() => RegisterJob(x => x.WithIntervalInMinutes(1).RepeatForever());
46+
public ScheduleLifeCycleBuilder EveryFiveMinutes() => RegisterJob(x => x.WithIntervalInMinutes(5).RepeatForever());
47+
public ScheduleLifeCycleBuilder EveryTenMinutes() => RegisterJob(x => x.WithIntervalInMinutes(10).RepeatForever());
6748

68-
public ScheduleLifeCycleBuilder EveryFifteenMinutes()
69-
{
70-
return RegisterJob(x => x.WithIntervalInMinutes(15).RepeatForever());
71-
}
49+
public ScheduleLifeCycleBuilder EveryFifteenMinutes() =>
50+
RegisterJob(x => x.WithIntervalInMinutes(15).RepeatForever());
7251

73-
public ScheduleLifeCycleBuilder EveryThirtyMinutes()
74-
{
75-
return RegisterJob(x => x.WithIntervalInMinutes(30).RepeatForever());
76-
}
52+
public ScheduleLifeCycleBuilder EveryThirtyMinutes() =>
53+
RegisterJob(x => x.WithIntervalInMinutes(30).RepeatForever());
7754

78-
public ScheduleLifeCycleBuilder Hourly()
79-
{
80-
return RegisterJob(x => x.WithIntervalInHours(1).RepeatForever());
81-
}
55+
public ScheduleLifeCycleBuilder Hourly() => RegisterJob(x => x.WithIntervalInHours(1).RepeatForever());
8256

83-
public ScheduleLifeCycleBuilder HourlyAt(int minutesAfterTheHour)
84-
{
85-
return RegisterJob($"0 {minutesAfterTheHour} * * * ?");
86-
}
57+
public ScheduleLifeCycleBuilder HourlyAt(int minutesAfterTheHour) =>
58+
RegisterJob($"0 {minutesAfterTheHour} * * * ?");
8759

88-
public ScheduleLifeCycleBuilder Daily()
89-
{
90-
return RegisterJob(x => x.WithIntervalInHours(24).RepeatForever());
91-
}
60+
public ScheduleLifeCycleBuilder Daily() => RegisterJob(x => x.WithIntervalInHours(24).RepeatForever());
9261

93-
public ScheduleLifeCycleBuilder DailyAt(int hours, int minutes, int seconds = 0)
94-
{
95-
return RegisterJob(x => x.StartingDailyAt(new TimeOfDay(hours, minutes, seconds)));
96-
}
62+
public ScheduleLifeCycleBuilder DailyAt(int hours, int minutes, int seconds = 0) =>
63+
RegisterJob(x => x.StartingDailyAt(new TimeOfDay(hours, minutes, seconds)));
9764
}

src/InEngine/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
namespace InEngine;
66

7-
class Program
7+
public static class Program
88
{
99
public static ServerHost ServerHost { get; set; }
1010

1111
private static void Main(string[] args)
1212
{
1313
/*
1414
* Set current working directory as services use the system directory by default.
15-
* Also, maybe run from the CLI from a different directory than the application root.
15+
* Also, allow running the CLI from a different directory than the application root.
1616
*/
1717
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
1818
new ArgumentInterpreter().Interpret(args);

0 commit comments

Comments
 (0)