コード例 #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));
            }
        }
コード例 #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;
            }
        }
コード例 #3
0
ファイル: Job.cs プロジェクト: azekeal/distributed
        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;
            }
        }
コード例 #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();
            }
        }
コード例 #5
0
ファイル: AgentPool.cs プロジェクト: azekeal/distributed
 public AgentPool(Distributed.Dispatcher dispatcher)
 {
     this.dispatcher = dispatcher;
 }