public void RemoveFromQueue() { _storage.UseConnection(connection => { connection.Execute($@"delete from [{_storage.SchemaName}.JobQueue] where Id = @id", new { id = Id }); }, true); }
public void RemoveFromQueue() { _storage.UseConnection(connection => { connection.Execute(string.Format(@" delete from [{0}.JobQueue] where Id = @id", _storage.GetSchemaName()), new { id = Id }); }, true); }
public void Execute(CancellationToken cancellationToken) { foreach (var table in ProcessedTables) { Logger.DebugFormat("Removing outdated records from table '{0}'...", table); int removedCount = 0; do { _storage.UseConnection(connection => { removedCount = connection.Execute( String.Format(@" delete from [{0}.{1}] where Id in ( select Id from [{0}.{1}] where ExpireAt < @expireAt limit @limit)", _storage.GetSchemaName(), table), new { limit = NumberOfRecordsInSinglePass, expireAt = DateTime.UtcNow }); }, true); if (removedCount > 0) { Logger.Trace(String.Format("Removed {0} outdated record(s) from '{1}' table.", removedCount, table)); cancellationToken.WaitHandle.WaitOne(DelayBetweenPasses); cancellationToken.ThrowIfCancellationRequested(); } } while (removedCount != 0); } cancellationToken.WaitHandle.WaitOne(_checkInterval); }
private T UseConnection <T>(Func <SQLiteConnection, T> action, bool isWriteLock = false) { return(_storage.UseConnection(action, isWriteLock)); }
public override string CreateExpiredJob( Job job, IDictionary <string, string> parameters, DateTime createdAt, TimeSpan expireIn) { if (job == null) { throw new ArgumentNullException("job"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } string createJobSql = string.Format(@" insert into [{0}.Job] (InvocationData, Arguments, CreatedAt, ExpireAt) values (@invocationData, @arguments, @createdAt, @expireAt); SELECT last_insert_rowid()", _storage.GetSchemaName()); var invocationData = InvocationData.Serialize(job); return(_storage.UseConnection(connection => { var jobId = connection.Query <int>( createJobSql, new { invocationData = JobHelper.ToJson(invocationData), arguments = invocationData.Arguments, createdAt = createdAt, expireAt = createdAt.Add(expireIn) }).Single().ToString(); if (parameters.Count > 0) { var parameterArray = new object[parameters.Count]; int parameterIndex = 0; foreach (var parameter in parameters) { parameterArray[parameterIndex++] = new { jobId = jobId, name = parameter.Key, value = parameter.Value }; } string insertParameterSql = string.Format(@" insert into [{0}.JobParameter] (JobId, Name, Value) values (@jobId, @name, @value)", _storage.GetSchemaName()); connection.Execute(insertParameterSql, parameterArray); } return jobId; }, true)); }