Skip to content

Commit

Permalink
Handling nul cases for Triggers and jobs for #103
Browse files Browse the repository at this point in the history
  • Loading branch information
guryanovev committed May 19, 2023
1 parent 430b9dd commit 0e22b48
Show file tree
Hide file tree
Showing 32 changed files with 103 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class DialogViewModel<TResult> implements IDialogViewModel<TResult> {
accepted = new js.Event<any>();
canceled = new js.Event<any>();
state = new js.ObservableValue<DataState>();
errorMessage = new js.ObservableValue<string>();

constructor() {
this.state.setValue('unknown');
Expand All @@ -19,4 +20,9 @@ export class DialogViewModel<TResult> implements IDialogViewModel<TResult> {
cancel() {
this.canceled.trigger({});
}

protected goToErrorState(message) {
this.state.setValue('error');
this.errorMessage.setValue(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DialogViewModel } from '../dialog-view-model';
import { CommandService } from '../../services';
import { CommandService, ErrorInfo } from '../../services';
import { Job, JobDetails, PropertyValue } from '../../api';
import { GetJobDetailsCommand } from '../../commands/job-commands';
import { Property, PropertyType } from '../common/property';
Expand All @@ -18,7 +18,7 @@ export default class JobDetailsViewModel extends DialogViewModel<any> {

loadDetails() {
this.commandService
.executeCommand<JobDetails>(new GetJobDetailsCommand(this.job.GroupName, this.job.Name))
.executeCommand<JobDetails>(new GetJobDetailsCommand(this.job.GroupName, this.job.Name), true)
.done(details => {
this.identity.setValue([
new Property('Name', this.job.Name, PropertyType.String),
Expand All @@ -42,8 +42,11 @@ export default class JobDetailsViewModel extends DialogViewModel<any> {

this.state.setValue('ready');
} else {
this.state.setValue('error');
this.goToErrorState('No details found, the Job no longer available.')
}
})
.fail((error: ErrorInfo) => {
this.goToErrorState(error.errorMessage);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default class JobDetailsView extends DialogViewBase<ViewModel> {

dom('.js_identity').observes(viewModel.identity, PropertyView);
dom('.js_summary').observes(viewModel.summary, PropertyView);
dom('.js_stateError').observes(viewModel.errorMessage);

RENDER_PROPERTIES(dom('.js_jobDataMap'), viewModel.jobDataMap);

viewModel.loadDetails();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@ <h2>Job details</h2>
</header>

<div class="dialog-content dialog-content-no-padding">

</div>

<div class="dialog-content dialog-content-no-padding">
<div class="properties-panel">
<header>Identity</header>
<table class="js_identity"></table>
</div>

<div class="dialog-loading-message js_stateUnknown">
Loading Job details...
</div>

<div class="dialog-global-error js_stateError">
No details found, the Job no longer available.

</div>

<div class="js_stateReady">
<div class="properties-panel">
<header>Identity</header>
<table class="js_identity"></table>
</div>
<div class="properties-panel">
<header>Summary</header>
<table class="js_summary"></table>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {DialogViewModel} from '../dialog-view-model';
import {CommandService} from '../../services';
import { DialogViewModel } from '../dialog-view-model';
import { CommandService, ErrorInfo } from '../../services';
import {CronTriggerType, PropertyValue, SimpleTriggerType, Trigger, TriggerDetails} from '../../api';
import {GetTriggerDetailsCommand} from '../../commands/trigger-commands';
import {Property, PropertyType} from '../common/property';
Expand All @@ -22,12 +22,12 @@ export class TriggerDetailsViewModel extends DialogViewModel<any> {

loadDetails() {
this.commandService
.executeCommand<TriggerDetails>(new GetTriggerDetailsCommand(this.trigger.GroupName, this.trigger.Name))
.executeCommand<TriggerDetails>(new GetTriggerDetailsCommand(this.trigger.GroupName, this.trigger.Name), true)
.done(details => {
const trigger = details.trigger;

if (!trigger) {
this.state.setValue('error');
this.goToErrorState('No details found, the trigger no longer available.')
return;
}

Expand Down Expand Up @@ -78,6 +78,9 @@ export class TriggerDetailsViewModel extends DialogViewModel<any> {
this.jobDataMap.setValue(details.jobDataMap);

this.state.setValue('ready');
})
.fail((error: ErrorInfo) => {
this.goToErrorState(error.errorMessage);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class TriggerDetailsView extends DialogViewBase<TriggerDetailsViewModel>
dom('.js_summary').observes(viewModel.summary, PropertyView);
dom('.js_identity').observes(viewModel.identity, PropertyView);
dom('.js_schedule').observes(viewModel.schedule, PropertyView);
dom('.js_stateError').observes(viewModel.errorMessage);

RENDER_PROPERTIES(dom('.js_jobDataMap'), viewModel.jobDataMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ <h2>Trigger details</h2>
</div>

<div class="dialog-global-error js_stateError">
No details found, the trigger no longer available.
</div>

<div class="js_stateReady">
Expand Down
7 changes: 5 additions & 2 deletions src/CrystalQuartz.Application.Client/app/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CommandService {
this._minEventId = 0;
}

executeCommand<T>(command: ICommand<T>): JQueryPromise<T> {
executeCommand<T>(command: ICommand<T>, suppressError: boolean = false): JQueryPromise<T> {
var result = $.Deferred(),
data = __assign(command.data, { command: command.code, minEventId: this._minEventId }),
that = this;
Expand Down Expand Up @@ -79,7 +79,10 @@ export class CommandService {
})
.fail(function (response) {
var comandResult = <ErrorInfo>response;
that.onCommandFailed.trigger(comandResult);

if (!suppressError || comandResult.disconnected) {
that.onCommandFailed.trigger(comandResult);
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class FakeSchedulerServer {
tpt: null,
v: 'In-Browser Emulation'
}),
'get_job_details': (args) => ({
/*'get_job_details': (args) => ({
_ok: true,
jd: {
ced: true, // ConcurrentExecutionDisallowed
Expand Down Expand Up @@ -143,13 +143,7 @@ export class FakeSchedulerServer {
}
}
} // todo: take actual from job
}),
'get_trigger_details': (args) => {
return {
_ok: true,
}

},
}),*/
'start_scheduler': (args) => {
this._scheduler.start();
return this.mapCommonData(args);
Expand Down
2 changes: 1 addition & 1 deletion src/CrystalQuartz.Application/AsyncUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Task CompletedTask()
#if NETSTANDARD2_0_OR_GREATER || NET46_OR_GREATER
return Task.CompletedTask;
#elif NET40
return TaskEx.FromResult<object>(null);
return TaskEx.FromResult<object?>(null);
#else
return Task.FromResult<object>(null);
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/CrystalQuartz.Application/Commands/AddTriggerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AddTriggerCommand(

protected override async Task InternalExecute(AddTriggerInput input, AddTriggerOutput output)
{
IDictionary<string, object> jobDataMap = null;
IDictionary<string, object>? jobDataMap = null;

if (input.JobDataMap != null)
{
Expand All @@ -32,7 +32,7 @@ protected override async Task InternalExecute(AddTriggerInput input, AddTriggerO

foreach (JobDataItem item in input.JobDataMap)
{
RegisteredInputType inputType = _registeredInputTypes.FirstOrDefault(x => x.InputType.Code == item.InputTypeCode);
RegisteredInputType? inputType = _registeredInputTypes.FirstOrDefault(x => x.InputType.Code == item.InputTypeCode);
if (inputType == null)
{
/*
Expand Down
10 changes: 5 additions & 5 deletions src/CrystalQuartz.Application/SchedulerHostInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ private string GetFileLoadingErrorMessage(FileLoadException exception, Version q
return exception.Message;
}

private SchedulerHost CreateErrorHost(string primaryError, Version version = null, Exception exception = null) =>
private SchedulerHost CreateErrorHost(string primaryError, Version? version = null, Exception? exception = null) =>
new SchedulerHost(
version,
new[] { primaryError }.Concat(GetExceptionMessages(exception)).ToArray());

private static IEnumerable<string> GetExceptionMessages(Exception exception)
private static IEnumerable<string> GetExceptionMessages(Exception? exception)
{
if (exception == null)
{
Expand All @@ -209,7 +209,7 @@ private static IEnumerable<string> GetExceptionMessages(Exception exception)
}
}

private ISchedulerEngine CreateSchedulerEngineBy(Version quartzVersion)
private ISchedulerEngine? CreateSchedulerEngineBy(Version quartzVersion)
{
if (!_options.SchedulerEngineResolvers.ContainsKey(quartzVersion.Major))
{
Expand All @@ -219,9 +219,9 @@ private ISchedulerEngine CreateSchedulerEngineBy(Version quartzVersion)
return _options.SchedulerEngineResolvers[quartzVersion.Major].Invoke();
}

private static Assembly FindQuartzAssembly()
private static Assembly? FindQuartzAssembly()
{
Type quartzSchedulerType = Type.GetType("Quartz.IScheduler, Quartz");
Type? quartzSchedulerType = Type.GetType("Quartz.IScheduler, Quartz");
if (quartzSchedulerType == null)
{
return null;
Expand Down
12 changes: 6 additions & 6 deletions src/CrystalQuartz.AspNetCore/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ public static class ApplicationBuilderExtensions
public static void UseCrystalQuartz(
this IApplicationBuilder app,
Func<object> schedulerProvider,
AspNetCoreOptions aspNetCoreOptions = null)
AspNetCoreOptions? aspNetCoreOptions = null)
{
UseCrystalQuartz(app, schedulerProvider, null, aspNetCoreOptions);
}

public static void UseCrystalQuartz(
this IApplicationBuilder app,
Func<object> schedulerProvider,
CrystalQuartzOptions options,
AspNetCoreOptions aspNetCoreOptions = null)
CrystalQuartzOptions? options,
AspNetCoreOptions? aspNetCoreOptions = null)
{
ISchedulerProvider provider = new FuncSchedulerProvider(schedulerProvider);
UseCrystalQuartz(app, provider, options, aspNetCoreOptions);
Expand All @@ -30,16 +30,16 @@ public static void UseCrystalQuartz(
public static void UseCrystalQuartz(
this IApplicationBuilder app,
ISchedulerProvider schedulerProvider,
AspNetCoreOptions aspNetCoreOptions = null)
AspNetCoreOptions? aspNetCoreOptions = null)
{
UseCrystalQuartz(app, schedulerProvider, null, aspNetCoreOptions);
}

public static void UseCrystalQuartz(
this IApplicationBuilder app,
ISchedulerProvider schedulerProvider,
CrystalQuartzOptions options,
AspNetCoreOptions aspNetCoreOptions = null)
CrystalQuartzOptions? options,
AspNetCoreOptions? aspNetCoreOptions = null)
{
CrystalQuartzOptions actualOptions = options ?? new CrystalQuartzOptions();
AspNetCoreOptions actualAspNetCoreOptions = aspNetCoreOptions ?? new AspNetCoreOptions();
Expand Down
2 changes: 1 addition & 1 deletion src/CrystalQuartz.Build/Tasks/MergeBinariesTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ select CreateMergeTask(
.WithPrecondition(() => !_skipCore));
}

private ITask<Nothing> CreateMergeTask(string outputDllName, string[] inputAssembliesNames, string dotNetVersionAlias, string[] libs = null)
private ITask<Nothing> CreateMergeTask(string outputDllName, string[] inputAssembliesNames, string dotNetVersionAlias, string[]? libs = null)
{
IDirectory ilMergePackage = (_solution.Src/"packages").AsDirectory().Directories.Last(d => d.Name.StartsWith("ILRepack"));

Expand Down
2 changes: 1 addition & 1 deletion src/CrystalQuartz.Core.Quartz2/AsyncUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static Task<T> FromResult<T>(T result)
public static Task CompletedTask()
{
#if NET40
return TaskEx.FromResult<object>(null);
return TaskEx.FromResult<object?>(null);
#else
return Task.FromResult<object>(null);
#endif
Expand Down
19 changes: 10 additions & 9 deletions src/CrystalQuartz.Core.Quartz2/Quartz2SchedulerClerk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public Task<SchedulerData> GetSchedulerData()
FireInstanceId = x.FireInstanceId,
})
.ToList();

SchedulerData schedulerData = new SchedulerData
{
Name = scheduler.SchedulerName,
Expand All @@ -51,12 +52,12 @@ public Task<SchedulerData> GetSchedulerData()
return AsyncUtils.FromResult(schedulerData);
}

public Task<JobDetailsData> GetJobDetailsData(string name, string group)
public Task<JobDetailsData?> GetJobDetailsData(string name, string group)
{
var scheduler = _scheduler;
if (scheduler.IsShutdown)
{
return null;
return AsyncUtils.FromResult<JobDetailsData?>(null);
}

IJobDetail job;
Expand All @@ -71,15 +72,15 @@ public Task<JobDetailsData> GetJobDetailsData(string name, string group)
// scheduler in case when JobType requires an external
// assembly to be referenced.
// see https://github.com/guryanovev/CrystalQuartz/issues/16 for details
return AsyncUtils.FromResult(new JobDetailsData(null, null));
return AsyncUtils.FromResult<JobDetailsData?>(new JobDetailsData(null, null));
}

if (job == null)
{
return null;
return AsyncUtils.FromResult<JobDetailsData?>(null);
}

return AsyncUtils.FromResult(new JobDetailsData(
return AsyncUtils.FromResult<JobDetailsData?>(new JobDetailsData(
GetJobDetails(job),
job.JobDataMap.ToDictionary(x => x.Key, x => x.Value)));
}
Expand Down Expand Up @@ -109,21 +110,21 @@ public Task<SchedulerDetails> GetSchedulerDetails()
});
}

public Task<TriggerDetailsData> GetTriggerDetailsData(string name, string group)
public Task<TriggerDetailsData?> GetTriggerDetailsData(string name, string group)
{
var scheduler = _scheduler;
if (scheduler.IsShutdown)
{
return null;
return AsyncUtils.FromResult<TriggerDetailsData?>(null);
}

ITrigger trigger = scheduler.GetTrigger(new TriggerKey(name, group));
if (trigger == null)
{
return null;
return AsyncUtils.FromResult<TriggerDetailsData?>(null);
}

return AsyncUtils.FromResult(new TriggerDetailsData
return AsyncUtils.FromResult<TriggerDetailsData?>(new TriggerDetailsData
{
PrimaryTriggerData = GetTriggerData(scheduler, trigger),
SecondaryTriggerData = GetTriggerSecondaryData(trigger),
Expand Down
4 changes: 2 additions & 2 deletions src/CrystalQuartz.Core.Quartz2/Quartz2SchedulerCommander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Task ScheduleJob(
string jobGroup,
string triggerName,
TriggerType trigger,
IDictionary<string, object> jobData)
IDictionary<string, object>? jobData)
{
TriggerBuilder triggerBuilder = ApplyTriggerData(
triggerName,
Expand All @@ -48,7 +48,7 @@ public Task ScheduleJob(
Type jobType,
string triggerName,
TriggerType triggerType,
IDictionary<string, object> jobData)
IDictionary<string, object>? jobData)
{
var jobBuilder = JobBuilder.Create(jobType);

Expand Down
2 changes: 1 addition & 1 deletion src/CrystalQuartz.Core.Quartz2/Quartz2SchedulerEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Task<object> CreateStandardRemoteScheduler(string url)
return AsyncUtils.FromResult<object>(schedulerFactory.GetScheduler());
}

private ISchedulerEventSource CreateEventSource(IScheduler scheduler, Options options)
private ISchedulerEventSource? CreateEventSource(IScheduler scheduler, Options options)
{
if (!scheduler.GetMetaData().SchedulerRemote)
{
Expand Down
Loading

0 comments on commit 0e22b48

Please sign in to comment.