Пример #1
0
        public async Task <IEnumerable <ElementState> > RunAsync()
        {
            var results = new List <ElementState>();

            //Parallel.ForEach(_tests.Where(t => t.IsDue), async test => { });
            foreach (var test in Tests.Where(t => t.IsDue))
            {
                try
                {
                    var result = await test.ExecuteAsync();

                    lock (results)
                    {
                        results.Add(result);
                    }

                    await _stateProcessor.ProcessAsync(test.Definition, result);

                    await _ruleProcessor.ProcessAsync(test.Definition, result);

                    Log.Debug("Test {type} ({id}) {state}",
                              test.GetType().Name,
                              test.Id,
                              result);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, ex.Message);
                }
            }

            // @TODO: So, if we're actually writing stuff away to the db as part of this, then it might take a while: We might be
            //        better off queing it up for later, and doing some kind of batch insert.
            await _valuesRepository.Add(results);

            return(results);
        }
Пример #2
0
        /// <summary>
        /// Return results of Argos instances have been updated
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <ArgosResult> > RunAsync()
        {
            var items = new List <ArgosResult>();

            foreach (var instance in Instances.Where(a => a.IsDue))
            {
                try
                {
                    //Log.Debug("Running {type} - {name}", instance.GetType().Name, instance.Id);

                    // Run instance
                    var result = await instance.RunAsync();

                    await _stateProcessor.ProcessAsync(instance.Definition, result.Items);

                    await _ruleProcessor.ProcessAsync(instance.Definition, result.Items);

                    // Check if state has changed since last time
                    ArgosResult previous = null;
                    if (_state.ContainsKey(instance.Id))
                    {
                        previous = _state[instance.Id];
                    }

                    if (!Compare.IsEqual(result, previous))
                    {
                        items.Add(result);

                        // #hack: dump result
                        Log.Debug(result.ToString());
                    }

                    _state[instance.Id] = result.Copy();
                }
                catch (Exception ex)
                {
                    Log.Error(ex, ex.Message);
                }
            }

            #region original
            //// Get any argos definitions who's heartbeat is due
            //foreach (var definition in GetDue())
            //         {
            //	try
            //	{
            //                 ArgosResult lastRun;
            //                 if (_state.ContainsKey(definition.Id))
            //                 {
            //                     lastRun = _state[definition.Id];
            //                 }
            //                 else
            //                 {
            //                     lastRun = new ArgosResult();
            //                     _state.Add(definition.Id, lastRun);
            //                 }

            //                 var argos = _argos.Single(t => t.GetType().Name == definition.Type);

            //		//Validate(testdefinition, test.Meta);
            //		Log.Debug("Running {type} - {name}", argos.GetType().Name, definition.Id);

            //		var rs = await argos.RunAsync(definition);

            //		foreach(var item in rs.Items)
            //		{
            //			await _stateProcessor.ProcessAsync(definition, item);
            //			await _ruleProcessor.ProcessAsync(definition, item);
            //		}

            //                 if (!Compare.ArgosResultsAreEqual(rs, lastRun))
            //                 {
            //                     //Log.Information("{argos} '{id}' Has changed: " + rs,
            //                     //    argos.GetType().Name,
            //                     //    definition.Id);

            //                     items.Add(rs);
            //                 }

            //                 _state[definition.Id] = rs;
            //             }
            //             catch (Exception ex)
            //             {
            //                 Log.Error(ex, ex.Message);
            //             }
            //         }
            #endregion

            return(items);
        }