Skip to content

Commit 4ccdda2

Browse files
committed
Fixed sync IO issue on 404 response, added support for readonly mode on backend side
1 parent 98d5e02 commit 4ccdda2

File tree

9 files changed

+83
-7
lines changed

9 files changed

+83
-7
lines changed

src/CommonAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
using System.Reflection;
1111

1212
[assembly: AssemblyProductAttribute("CrystalQuartz")]
13-
[assembly: AssemblyVersionAttribute("7.2.0.0")]
14-
[assembly: AssemblyFileVersionAttribute("7.2.0.0")]
13+
[assembly: AssemblyVersionAttribute("7.3.0.0")]
14+
[assembly: AssemblyFileVersionAttribute("7.3.0.0")]

src/CrystalQuartz.Application/CrystalQuartzOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public static RegisteredInputType[] CreateDefaultJobDataMapInputTypes()
7777
public Type[]? AllowedJobTypes { get; set; }
7878

7979
public Action<Exception>? OnUnhandledPanelException { get; set; }
80+
81+
public bool ReadOnly { get; set; } = false;
8082
}
8183

8284
public class ConfigurableTraversingOptions

src/CrystalQuartz.Application/SchedulerHostInitializer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ private async Task<SchedulerHost> CreateSchedulerHostInternal()
148148
services.EventSource.EventEmitted += (sender, args) => { eventHub.Push(args.Payload); };
149149
}
150150

151+
ISchedulerCommander schedulerCommander = _options.ReadOnly
152+
? new ReadOnlySchedulerCommander()
153+
: services.Commander;
154+
151155
return new ReadySchedulerHost(
152156
services.Clerk,
153-
services.Commander,
157+
schedulerCommander,
154158
quartzVersion,
155159
eventHub,
156160
eventHub,

src/CrystalQuartz.Application/Startup/OptionsUtils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public static Options ToRuntimeOptions(
3838
jobResultAnalyzer,
3939
options.JobDataMapInputTypes,
4040
options.AllowedJobTypes ?? new Type[0],
41-
options.OnUnhandledPanelException);
41+
options.OnUnhandledPanelException,
42+
options.ReadOnly);
4243
}
4344

4445
private static IJobResultAnalyzer CreateJobResultAnalyzer(JobResultAnalyserOptions options)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace CrystalQuartz.Core.Contracts
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Threading.Tasks;
6+
using CrystalQuartz.Core.Domain.TriggerTypes;
7+
8+
public class ReadOnlySchedulerCommander : ISchedulerCommander
9+
{
10+
public Task ScheduleJob(
11+
string jobName,
12+
string jobGroup,
13+
string? triggerName,
14+
TriggerType trigger,
15+
IDictionary<string, object>? jobData) => Fail();
16+
17+
public Task ScheduleJob(
18+
string? jobName,
19+
string? jobGroup,
20+
Type jobType,
21+
string? triggerName,
22+
TriggerType triggerType,
23+
IDictionary<string, object>? jobData) => Fail();
24+
25+
public Task DeleteJobGroup(string jobGroup) => Fail();
26+
27+
public Task DeleteJob(string jobName, string jobGroup) => Fail();
28+
29+
public Task DeleteTrigger(string triggerName, string triggerGroup) => Fail();
30+
31+
public Task ExecuteNow(string jobName, string jobGroup) => Fail();
32+
33+
public Task PauseAllJobs() => Fail();
34+
35+
public Task PauseJobGroup(string jobGroup) => Fail();
36+
37+
public Task PauseJob(string jobName, string jobGroup) => Fail();
38+
39+
public Task PauseTrigger(string triggerName, string triggerGroup) => Fail();
40+
41+
public Task ResumeAllJobs() => Fail();
42+
43+
public Task ResumeJobGroup(string jobGroup) => Fail();
44+
45+
public Task ResumeJob(string jobName, string jobGroup) => Fail();
46+
47+
public Task ResumeTrigger(string triggerName, string triggerGroup) => Fail();
48+
49+
public Task StandbyScheduler() => Fail();
50+
51+
public Task StartScheduler() => Fail();
52+
53+
public Task StopScheduler() => Fail();
54+
55+
private Task Fail()
56+
{
57+
throw new Exception("Could not perform this action, the scheduler is read-only.");
58+
}
59+
}
60+
}

src/CrystalQuartz.Core/Options.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public Options(
2626
IJobResultAnalyzer jobResultAnalyzer,
2727
RegisteredInputType[] jobDataMapInputTypes,
2828
Type[] allowedJobTypes,
29-
Action<Exception> errorAction)
29+
Action<Exception> errorAction,
30+
bool readOnly)
3031
{
3132
TimelineSpan = timelineSpan;
3233
SchedulerEngineResolvers = schedulerEngineResolvers;
@@ -41,6 +42,7 @@ public Options(
4142
JobDataMapInputTypes = jobDataMapInputTypes;
4243
AllowedJobTypes = allowedJobTypes;
4344
ErrorAction = errorAction;
45+
ReadOnly = readOnly;
4446
}
4547

4648
public TimeSpan TimelineSpan { get; }
@@ -68,5 +70,7 @@ public Options(
6870
public Type[] AllowedJobTypes { get; }
6971

7072
public Action<Exception> ErrorAction { get; }
73+
74+
public bool ReadOnly { get; }
7175
}
7276
}

src/CrystalQuartz.WebFramework/Request/AbstractFileRequestHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public RequestHandlingResult WriteResourceToStream(string resourceName, IRequest
2626
404,
2727
async stream =>
2828
{
29+
#if NETSTANDARD2_1_OR_GREATER
30+
await using var output = new StreamWriter(stream);
31+
#else
2932
using var output = new StreamWriter(stream);
33+
#endif
3034
await output.WriteLineAsync("Not found");
3135
}));
3236
}

src/CrystalQuartz.WebFramework/Request/FileRequestHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public FileRequestHandler(Assembly resourcesAssembly, string resourcePrefix)
1212

1313
protected override string? GetPath(IRequest request)
1414
{
15-
return request["path"];
15+
return request["path"]?.TrimStart('/'); // We only need this Trim call because of the bug https://github.com/jantimon/html-webpack-plugin/issues/694
1616
}
1717
}
1818
}

src/Demo.Quartz3.DotNetCore3/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Demo.Quartz3.DotNetCore3
55
using System.Collections.Generic;
66
using System.Collections.Specialized;
77
using System.Threading.Tasks;
8+
using CrystalQuartz.Application;
89
using CrystalQuartz.AspNetCore;
910
using Microsoft.AspNetCore;
1011
using Microsoft.AspNetCore.Hosting;
@@ -21,7 +22,7 @@ static async Task Main(string[] args)
2122
.CreateDefaultBuilder()
2223
.Configure(app =>
2324
{
24-
app.UseCrystalQuartz(() => scheduler);
25+
app.UseCrystalQuartz(() => scheduler, new CrystalQuartzOptions { ReadOnly = true });
2526
});
2627

2728
await builder.Build().RunAsync();

0 commit comments

Comments
 (0)