Class UpdateRowLockHandler
- Namespace
- Quartz.Impl.AdoJobStore
- Assembly
- Quartz.dll
Provide thread/resource locking in order to protect resources from being altered by multiple threads at the same time using a db row update.
public class UpdateRowLockHandler : DbLockHandler, ILockHandler
- Inheritance
-
UpdateRowLockHandler
- Implements
- Derived
- Inherited Members
Remarks
Note: This lock handler is useful for databases that do not support row locking via "SELECT FOR UPDATE" or SQL Server's type syntax.
As of Quartz.NET 2.0 version there is no need to use this implementation for SQL Server databases.
Constructors
UpdateRowLockHandler(IDbProvider)
Initializes a new instance of the UpdateRowLockHandler class.
public UpdateRowLockHandler(IDbProvider provider)
Parameters
providerIDbProvider
UpdateRowLockHandler(string, string?, string, string, IDbProvider)
Initializes a new instance of the UpdateRowLockHandler class for a derived
handler that spells its own statements — a dialect whose UPDATE needs a hint, for instance.
protected UpdateRowLockHandler(string tablePrefix, string? schedulerName, string updateForLockSql, string insertLockSql, IDbProvider dbProvider)
Parameters
tablePrefixstringThe table prefix the store was configured with.
schedulerNamestringThe scheduler whose lock rows these are.
updateForLockSqlstringThe statement that takes the lock.
insertLockSqlstringThe statement that creates the lock row.
dbProviderIDbProviderThe database the statements run against.
Fields
InsertLock
The statement that inserts the lock row when it does not exist yet.
protected const string InsertLock = "INSERT INTO {0}LOCKS(SCHED_NAME, LOCK_NAME) VALUES (@schedulerName, @lockName)"
Field Value
UpdateForLock
The statement that takes the lock by updating its row.
protected const string UpdateForLock = "UPDATE {0}LOCKS SET LOCK_NAME = LOCK_NAME WHERE SCHED_NAME = @schedulerName AND LOCK_NAME = @lockName"
Field Value
Properties
RetryCount
How many times a contended lock attempt is retried before it fails.
protected virtual int RetryCount { get; }
Property Value
RetryPeriod
Sleep between attempts, defaults to 1 second.
[TimeSpanParseRule(TimeSpanParseRule.Milliseconds)]
public TimeSpan RetryPeriod { get; init; }
Property Value
Remarks
It was a literal TimeSpan.FromSeconds(1) in the retry loop, which meant this handler
ignored quartz.jobStore.lockHandler.retryPeriod while its sibling
SelectForUpdateLockHandler honoured it. Init-only for the same reason as there: the
value is fixed for the life of the handler, and the property bridge writes it by reflection,
which an init accessor does not stop.
Methods
ExecuteSql(Guid, ConnectionAndTransactionHolder, string, string, string, CancellationToken)
Execute the SQL that will lock the proper database row.
protected override ValueTask ExecuteSql(Guid requestorId, ConnectionAndTransactionHolder conn, string lockName, string expandedSql, string expandedInsertSql, CancellationToken cancellationToken = default)
Parameters
requestorIdGuidconnConnectionAndTransactionHolderlockNamestringexpandedSqlstringexpandedInsertSqlstringcancellationTokenCancellationToken