public AgentConnection(Distributed.Dispatcher dispatcher, EndpointConnectionInfo info) { using (Trace.Log()) { connection = new HubConnection($"http://{info.signalrUrl}/", dispatcher.Identifier, dispatcher.SignalrUrl, dispatcher.WebUrl, "DispatcherHub"); connection.StateChanged += s => { currentState = s.NewState; StateChanged?.Invoke(s); if (currentState == ConnectionState.Disconnected) { if (s.OldState == ConnectionState.Connecting) { if (retryCount++ > MaxRetryCount) { connection.Stop(); dispatcher.ReleaseAgent(info.name); } } if (disposed) { stopped.Set(); } } }; connection.Proxy.On <string, bool>("SetAgentState", (id, active) => SetAgentState?.Invoke(id, active)); connection.Proxy.On <TaskItem, TaskResult>("CompleteTask", (taskItem, taskResult) => TaskCompleted?.Invoke(taskItem, taskResult)); } }
public override void Dispose() { using (Trace.Log()) { Console.WriteLine($"Disposing {Identifier}"); Disposed?.Invoke(this); disposed = true; activeJob?.CancelTasks(pendingTasks.Values); activeJob?.CancelTasks(activeTasks.Values); activeJob = null; activeTasks?.Clear(); pendingTasks?.Clear(); if (dispatcher != null) { dispatcher.ActiveJobChanged -= OnActiveJobChanged; dispatcher = null; } connection?.Dispose(); connection = null; TaskStateChanged = null; } }
public Job(Distributed.Dispatcher dispatcher, ITaskProvider taskProvider, int priority) { using (Trace.Log()) { this.Dispatcher = dispatcher; this.Name = $"job_{Guid.NewGuid()}"; this.Priority = priority; this.TaskCount = taskProvider.TaskCount; this.taskProvider = taskProvider; this.taskProvider.TasksAdded += NotifyTasksAvailable; stats.pending = taskProvider.TaskCount; } }
public Agent(Distributed.Dispatcher dispatcher, EndpointConnectionInfo info) : base(info) { using (Trace.Log()) { this.dispatcher = dispatcher; this.pendingTasks = new ConcurrentDictionary <string, TaskItem>(); this.activeTasks = new ConcurrentDictionary <string, TaskItem>(); this.dispatcher.ActiveJobChanged += OnActiveJobChanged; this.connection = new AgentConnection(dispatcher, info); this.connection.StateChanged += (s) => { //if (s.OldState == ConnectionState.Connected && s.NewState == ConnectionState.Disconnected) //{ // dispatcher.ReleaseAgent(Identifier); //} }; this.connection.SetAgentState += SetAgentState; this.connection.TaskCompleted += OnTaskCompleted; this.connection.Start(); } }
public AgentPool(Distributed.Dispatcher dispatcher) { this.dispatcher = dispatcher; }