2

Is it possible to configure Quartz through a mixture of properties held in a config file (either quartz.properties or app.config / web.config) and also some via the StdSchedulerFactory constructor?

I would like to pass the AdoJobStore connectionstring via the constructor, as it is dynamic depending on the environment, but the rest of the settings are static so would be better placed in a config file.

I've tried passing in only the quartz.dataSource.myDS.connectionString property via the constructor, whilst having the rest of the properties in a quartz.config in the working directory. However, I get the error:

Provider not specified for DataSource: myDS

So I guess this means that if you use the constructor that accepts the NameValueCollection, then it doesn't bother checking the config file(s).

I know that the quartz.config file is in the right place, because if I put the connectionstring in there and use the default constructor, it all works

1 Answer 1

3

In the end, they are all simply named-value pairs.

You can have "most" of them in an .xml file...then "add in" the ones you want via code.

Or have all of them in code.

See the UnitTests for the source code, and you'll see this fairly clearly.

Something like this:

    NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("quartz");

    config.Add("MyCodedUpKey", "MyCodedUpValue");

If you have a "collision" (a "key" in the config file that you want to override..apply some simple name-valued-pair "update existing key" logic"

Check if Key Exists in NameValueCollection

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks, I've gone and implemented something like this (although I did note that the NameValueCollection that gets returned from the ConfigurationManager is read only, so you have to create a new collection, initialised with this read only one, and then I add the dynamic value
So, to confirm the answer to my question is that the StdSchedulerFactory will not automatically merge properties it finds in the quartz.config file and those passed in the constructor - you have to manually merge them and pass them all in the constructor :-)
No, I don't think so. You have to manually intervene. Which kinda makes sense...in the case of collisions. If they coded it up as "config wins" somebody would complain about that. If they coded it up as "code wins", somebody would complain about that.
Hmmm, it's a fair point. But personally I would be happy to accept an exception in a collision, in order to get the extra convenience (in my particular case)
If they threw an exception, somebody would complain about that (me thinks) :) ........ can't win for lose sometimes. Here is one of those situations........ in the Sql Server world : connect.microsoft.com/SQLServer/feedback/details/382007/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.