public override void AnnounceServer(string serverId, ServerContext context) { if (serverId == null) throw new ArgumentNullException(nameof(serverId)); if (context == null) throw new ArgumentNullException(nameof(context)); var data = new ServerData { WorkerCount = context.WorkerCount, Queues = context.Queues, StartedAt = DateTime.UtcNow, }; _storage.UseConnection(connection => { connection.Execute( $@";merge [{_storage.SchemaName}].Server with (holdlock) as Target using (VALUES (@id, @data, @heartbeat)) as Source (Id, Data, Heartbeat) on Target.Id = Source.Id when matched then update set Data = Source.Data, LastHeartbeat = Source.Heartbeat when not matched then insert (Id, Data, LastHeartbeat) values (Source.Id, Source.Data, Source.Heartbeat);", new { id = serverId, data = JobHelper.ToJson(data), heartbeat = DateTime.UtcNow }); }); }
public override void AnnounceServer(string serverId, ServerContext context) { if (serverId == null) throw new ArgumentNullException("serverId"); if (context == null) throw new ArgumentNullException("context"); var data = new ServerData { WorkerCount = context.WorkerCount, Queues = context.Queues, StartedAt = DateTime.UtcNow, }; _connection.Execute( @";merge HangFire.Server with (holdlock) as Target " + @"using (VALUES (@id, @data, @heartbeat)) as Source (Id, Data, Heartbeat) " + @"on Target.Id = Source.Id " + @"when matched then update set Data = Source.Data, LastHeartbeat = Source.Heartbeat " + @"when not matched then insert (Id, Data, LastHeartbeat) values (Source.Id, Source.Data, Source.Heartbeat);", new { id = serverId, data = JobHelper.ToJson(data), heartbeat = DateTime.UtcNow }); }
public override void AnnounceServer(string serverId, ServerContext context) { if (serverId == null) throw new ArgumentNullException(nameof(serverId)); if (context == null) throw new ArgumentNullException(nameof(context)); var data = new ServerData { WorkerCount = context.WorkerCount, Queues = context.Queues, StartedAt = DateTime.UtcNow, }; _storage.UseConnection(connection => { var sql = _storage.SqlServerSettings != null && !string.IsNullOrEmpty(_storage.SqlServerSettings.AnnounceServerSql) ? _storage.SqlServerSettings.AnnounceServerSql : @";merge [{0}].Server with (holdlock) as Target " + @"using (VALUES (@id, @data, @heartbeat)) as Source (Id, Data, Heartbeat) " + @"on Target.Id = Source.Id " + @"when matched then update set Data = Source.Data, LastHeartbeat = Source.Heartbeat " + @"when not matched then insert (Id, Data, LastHeartbeat) values (Source.Id, Source.Data, Source.Heartbeat);"; connection.Execute( string.Format(sql, _storage.SchemaName), new { id = serverId, data = JobHelper.ToJson(data), heartbeat = DateTime.UtcNow }); }); }