예제 #1
0
        /// <summary>
        /// .ctor
        /// Инициализируем акторы, добавляя обработчик завершения таска
        /// </summary>
        /// <param name="status"></param>
        /// <param name="nodeSettings"></param>
        public Node(IStatusService <StatusMessage> status, NodeSettings nodeSettings, IServiceProvider serviceProvider)
        {
            _status          = status;
            _nodeSettings    = nodeSettings;
            _serviceProvider = serviceProvider;


            for (var i = 0; i < nodeSettings.ActorsCount; i++)
            {
                var actor = new Actor(nodeSettings);
                actor.AddCallback("node", message =>
                {
                    var apiService = _serviceProvider.GetRequiredService <IApiService>();
                    var url        = string.Format("{0}/api/worker/taskComplete", _nodeSettings.ClusterUrl);
                    apiService.PutOrPostRequest <TaskComplete, string>(url, new TaskComplete()
                    {
                        TaskId = message.TaskId,
                        Host   = _nodeSettings.NodeUrl
                    });
                });

                _status.AddActor(Guid.NewGuid().ToString(), actor);
            }
        }