Reputation: 85
I'm exploring NCron to be used as a scheduler host for running several sftp jobs. Is there any way to restrict the job from running if already an existing instance is running? I have gone through the wiki but can't find any details on this.
Upvotes: 2
Views: 136
Reputation: 38346
Ensuring that a job is not executed multiple times in parallel can be done by wrapping the body of the Execute()
method in a lock
block. However, due to the nature of the lock
statement, this will cause executions of the job in question to be queued, which may or may not be what you want.
If you would rather that the execution of the job is skipped when the job is already running, this can be solved with a static bool
and and a little lock
, if
and try
. Here is a first and untested attempt at building a base class for such jobs: https://gist.github.com/schourode/7639291
I would love to receive feedback on this experiment. If successful, this could very well make it into the NCron core assembly.
Upvotes: 1