public override void AddTask(IDatabaseTask task) { ClassicVersionTask script = new ClassicVersionTask(this, task.FileName); script.ExecutionOrder = task.ExecutionOrder; this.Tasks.Add(script); }
public TaskSuggestion(IDatabaseTask task) { TaskId = task.Id; Name = task.Name; ProjectId = task.ProjectId; ProjectName = task.Project?.Name ?? ""; ProjectColor = task.Project?.Color ?? ""; }
public string WhoseTaskIsIt( RachisState state, IDatabaseTask task, Func <string> getLastResponsibleNode) { if (state == RachisState.Candidate || state == RachisState.Passive) { return(null); } var mentorNode = task.GetMentorNode(); if (mentorNode != null) { if (Members.Contains(mentorNode)) { return(mentorNode); } } var lastResponsibleNode = getLastResponsibleNode?.Invoke(); if (lastResponsibleNode != null) { return(lastResponsibleNode); } var topology = new List <string>(Members); topology.AddRange(Promotables); topology.AddRange(Rehabs); topology.Sort(); if (topology.Count == 0) { return(null); // this is probably being deleted now, no one is able to run tasks } var key = task.GetTaskKey(); while (true) { var index = (int)Hashing.JumpConsistentHash.Calculate(key, topology.Count); var entry = topology[index]; if (Members.Contains(entry)) { return(entry); } topology.RemoveAt(index); if (topology.Count == 0) { return(null); // all nodes in the topology are probably in rehab } // rehash so it will likely go to a different member in the cluster key = Hashing.Mix(key); } }
private Task(IDatabaseTask entity) : this(entity as ITask, entity.SyncStatus, entity.LastSyncErrorMessage, entity.IsDeleted) { User = entity.User == null ? null : Models.User.From(entity.User); Project = entity.Project == null ? null : Models.Project.From(entity.Project); Workspace = entity.Workspace == null ? null : Models.Workspace.From(entity.Workspace); SyncStatus = entity.SyncStatus; LastSyncErrorMessage = entity.LastSyncErrorMessage; IsDeleted = entity.IsDeleted; }
public void ExecuteTasks(ISession session) { int count = this.tasks.Count; for (int i = 1; i < count + 1; i++) { IDatabaseTask task = this.tasks.Dequeue(); task.Execute(session, i, count); } }
public void ShouldSetExecutionOrderOfTask() { // Arrange XElement element = new XElement( XName.Get("script"), new XAttribute(XName.Get("file"), "path/file.sql")); // Act IDatabaseTask task = this.factory.Create(element, 25, null); // Assert Assert.Equal(25, task.ExecutionOrder); }
public void ShouldSetFileNameOfScript() { // Arrange XElement element = new XElement( XName.Get("script"), new XAttribute(XName.Get("file"), "path/file.sql")); // Act IDatabaseTask task = this.factory.Create(element, 0, null); // Assert Assert.Equal("path/file.sql", ((ScriptTask)task).FileName); }
public void ShouldCreateScriptTask() { // Arrange XElement element = new XElement( XName.Get("script"), new XAttribute(XName.Get("file"), "path/file.sql")); // Act IDatabaseTask task = this.factory.Create(element, 0, null); // Assert Assert.IsType <ScriptTask>(task); }
public string WhoseTaskIsIt( RachisState state, IDatabaseTask task, Func <string> getLastResponsibleNode) { if (state == RachisState.Candidate || state == RachisState.Passive) { return(null); } var mentorNode = task.GetMentorNode(); if (mentorNode != null) { if (Members.Contains(mentorNode)) { return(mentorNode); } } var lastResponsibleNode = getLastResponsibleNode?.Invoke(); if (lastResponsibleNode != null) { return(lastResponsibleNode); } var topology = new List <string>(Members); topology.AddRange(Promotables); topology.AddRange(Rehabs); topology.Sort(); if (task.IsResourceIntensive() && Members.Count > 1) { // if resource intensive operation, we don't want to have it on the first node of the database topology return(FindNodeForIntensiveOperation(task.GetTaskKey(), topology)); } return(FindNode(task.GetTaskKey(), topology)); }
public string WhoseTaskIsIt( DatabaseTopology databaseTopology, IDatabaseTask configuration, IDatabaseTaskStatus taskStatus, bool useLastResponsibleNodeIfNoAvailableNodes = false) { var whoseTaskIsIt = databaseTopology.WhoseTaskIsIt( ServerStore.Engine.CurrentState, configuration, getLastReponsibleNode: () => ServerStore.LicenseManager.GetLastResponsibleNodeForTask( taskStatus, databaseTopology, configuration, NotificationCenter)); if (whoseTaskIsIt == null && useLastResponsibleNodeIfNoAvailableNodes) { return(taskStatus.NodeTag); } return(whoseTaskIsIt); }
public string WhoseTaskIsIt(IDatabaseTask task, bool inPassiveState) { if (inPassiveState) { return(null); } var topology = new List <string>(Members); topology.AddRange(Promotables); topology.AddRange(Rehabs); topology.Sort(); if (topology.Count == 0) { return(null); // this is probably being deleted now, no one is able to run tasks } var key = task.GetTaskKey(); while (true) { var index = (int)Hashing.JumpConsistentHash.Calculate(key, topology.Count); var entry = topology[index]; if (Members.Contains(entry)) { return(entry); } topology.RemoveAt(index); if (topology.Count == 0) { return(null); // all nodes in the topology are probably in rehab } // rehash so it will likely go to a different member in the cluster key = Hashing.Mix(key); } }
public RealmTask(IDatabaseTask entity, Realms.Realm realm) : this(entity as ITask, realm) { IsDirty = entity.IsDirty; }
public static Task From(IDatabaseTask entity) => new Task(entity);
public bool HasExecutedScript(VersionBase currentVersion, VersionBase targetVersion, IDatabaseTask task) { if (currentVersion != null) { NumericVersion currentNumericVersion = currentVersion as NumericVersion; NumericVersion targetNumericVersion = targetVersion as NumericVersion; if (currentNumericVersion.Version.Equals(targetNumericVersion.Version)) { return(currentNumericVersion.HasExecutedTask(task)); } } return(false); }
/// <summary> /// Returns whether a script belongs to the current version and if so whether it has already been executed /// </summary> /// <param name="currentVersion"></param> /// <param name="targetVersion"></param> /// <param name="task"></param> /// <returns></returns> public bool HasExecutedScript(VersionBase currentVersion, VersionBase targetVersion, IDatabaseTask task) { if (currentVersion != null) { ClassicVersion currentClassicVersion = currentVersion as ClassicVersion; ClassicVersion targetClassicVersion = targetVersion as ClassicVersion; if (currentClassicVersion.SystemVersion.Equals(targetClassicVersion.SystemVersion)) { return(currentClassicVersion.HasExecutedTask(task)); } } return(false); }
public abstract bool HasExecutedTask(IDatabaseTask task);
public abstract void AddTask(IDatabaseTask task);
public override bool HasExecutedTask(IDatabaseTask task) { return(this.Tasks.Contains(new ClassicVersionTask(this, task.FileName))); }
public void AddTask(IDatabaseTask task) { this.tasks.Enqueue(task); }