Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
        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;
            }
        }
Beispiel #4
0
        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();
            }
        }
Beispiel #5
0
 public AgentPool(Distributed.Dispatcher dispatcher)
 {
     this.dispatcher = dispatcher;
 }