Skip to content

Commit

Permalink
Use configured type loader in scheduler factory init (#2268)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Feb 4, 2024
1 parent 7d525f2 commit b3c98be
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
added to the constructor `CronExpression(SerializationInfo info, StreamingContext context)`.


## Release 3.8.1, Feb xx 2024

* Fix handling of env var quartz.config (#2212) (#2213)
* Use configured type loader in scheduler factory init (#2268)


## Release 3.8.0, Nov 18 2023

* CHANGES
Expand Down
38 changes: 18 additions & 20 deletions src/Quartz/Impl/StdSchedulerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,19 +406,32 @@ private async ValueTask<IScheduler> Instantiate()
string threadName = cfg.GetStringProperty(PropertySchedulerThreadName, "{0}_QuartzSchedulerThread".FormatInvariant(schedName))!;
var schedInstId = cfg.GetStringProperty(PropertySchedulerInstanceId, DefaultInstanceId)!;

// Create type load helper
Type? typeLoadHelperType = LoadType(cfg.GetStringProperty(PropertySchedulerTypeLoadHelperType));
ITypeLoadHelper loadHelper;
try
{
loadHelper = InstantiateType<ITypeLoadHelper>(typeLoadHelperType ?? typeof(SimpleTypeLoadHelper));
}
catch (Exception e)
{
ThrowHelper.ThrowSchedulerConfigException("Unable to instantiate type load helper: {0}".FormatInvariant(e.Message), e);
return default;
}

loadHelper.Initialize();

if (schedInstId.Equals(AutoGenerateInstanceId))
{
autoId = true;
instanceIdGeneratorType = LoadType(cfg.GetStringProperty(PropertySchedulerInstanceIdGeneratorType)) ?? typeof(SimpleInstanceIdGenerator);
instanceIdGeneratorType = loadHelper.LoadType(cfg.GetStringProperty(PropertySchedulerInstanceIdGeneratorType)) ?? typeof(SimpleInstanceIdGenerator);
}
else if (schedInstId.Equals(SystemPropertyAsInstanceId))
{
autoId = true;
instanceIdGeneratorType = typeof(SystemPropertyInstanceIdGenerator);
}

Type? typeLoadHelperType = LoadType(cfg.GetStringProperty(PropertySchedulerTypeLoadHelperType));

dbFailureRetry = cfg.GetTimeSpanProperty(PropertyJobStoreDbRetryInterval, dbFailureRetry);
if (dbFailureRetry < TimeSpan.Zero)
{
Expand All @@ -435,20 +448,6 @@ private async ValueTask<IScheduler> Instantiate()
var schedCtxtProps = cfg.GetPropertyGroup(PropertySchedulerContextPrefix, true);
var proxyScheduler = cfg.GetBooleanProperty(PropertySchedulerProxy, false);

// Create type load helper
ITypeLoadHelper loadHelper;
try
{
loadHelper = InstantiateType<ITypeLoadHelper>(typeLoadHelperType ?? typeof(SimpleTypeLoadHelper));
}
catch (Exception e)
{
ThrowHelper.ThrowSchedulerConfigException("Unable to instantiate type load helper: {0}".FormatInvariant(e.Message), e);
return default;
}

loadHelper.Initialize();

// If Proxying to remote scheduler, short-circuit here...
// ~~~~~~~~~~~~~~~~~~
if (proxyScheduler)
Expand Down Expand Up @@ -482,8 +481,7 @@ private async ValueTask<IScheduler> Instantiate()
return remoteScheduler;
}


Type? jobFactoryType = LoadType(cfg.GetStringProperty(PropertySchedulerJobFactoryType));
Type? jobFactoryType = loadHelper.LoadType(cfg.GetStringProperty(PropertySchedulerJobFactoryType));
IJobFactory? jobFactory = null;
if (jobFactoryType != null)
{
Expand Down Expand Up @@ -794,7 +792,7 @@ private async ValueTask<IScheduler> Instantiate()
ISchedulerPlugin plugin;
try
{
var pluginTypeType = LoadType(plugInType) ?? throw new SchedulerException($"Could not load plugin type {plugInType}");
var pluginTypeType = loadHelper.LoadType(plugInType) ?? throw new SchedulerException($"Could not load plugin type {plugInType}");
// we need to use concrete types to resolve correct one
var method = GetType().GetMethod(nameof(InstantiateType), BindingFlags.Instance | BindingFlags.NonPublic)!.MakeGenericMethod(pluginTypeType);
plugin = (ISchedulerPlugin) method.Invoke(this, new [] { pluginTypeType! })!;
Expand Down
4 changes: 2 additions & 2 deletions src/Quartz/Simpl/SimpleTypeLoadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Quartz.Simpl;
internal sealed class SimpleTypeLoadHelper : ITypeLoadHelper
{
private const string QuartzAssemblyTypePostfix = ", Quartz";
private const string QuartzJobsAssemblyTypePostifx = ", Quartz.Jobs";
private const string QuartzJobsAssemblyTypePostfix = ", Quartz.Jobs";

/// <inheritdoc />
public void Initialize()
Expand All @@ -48,7 +48,7 @@ public void Initialize()
if (type == null && name.EndsWith(QuartzAssemblyTypePostfix, StringComparison.Ordinal))
{
// we've moved jobs to new assembly try that too
var newName = name.Substring(0, name.Length - QuartzAssemblyTypePostfix.Length) + QuartzJobsAssemblyTypePostifx;
var newName = name.Substring(0, name.Length - QuartzAssemblyTypePostfix.Length) + QuartzJobsAssemblyTypePostfix;
type = Type.GetType(newName);
}
if (type == null)
Expand Down

0 comments on commit b3c98be

Please sign in to comment.