Пример #1
0
        static Dictionary <Executor.TaskState, int> GetTaskStatesCount(ulong[] taskIds)
        {
            using (var service = new Executor.ExecutionBrokerServiceClient())
            {
                var taskInfos   = service.GetBriefTaskList();
                var statesCount = taskInfos
                                  .Where(info => taskIds.Contains(info.TaskId))
                                  .GroupBy(info => info.State)
                                  .ToDictionary(group => group.Key, group => group.Count());

                return(statesCount);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            using (var service = new Executor.ExecutionBrokerServiceClient())
            {
                if (Program.MagicHappens() || service.MagicHappens())
                {
                    Console.WriteLine("Magic happened here or on the service side. Returning...");
                    return;
                }
            }

            new Thread(() => LaunchTasks()).Start();
            new Thread(() => WatchTasks()).Start();
        }
Пример #3
0
        static void LaunchTasks()
        {
            var resourceNames = GetAllowedResourceNames(PACK_NAME);

            for (int iterNum = 0; LAUNCHES_COUNT < 0 || iterNum < LAUNCHES_COUNT; iterNum++)
            {
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        using (var executor = new Executor.ExecutionBrokerServiceClient())
                        {
                            ulong taskId = executor.GetNewTaskId();

                            string specificResourceName = null;
                            if (GetNextRandom(100) < 10) // on every N%'th launch
                            {
                                specificResourceName = resourceNames[GetNextRandom(resourceNames.Length)];
                                Console.WriteLine("{0} on {1}", taskId, specificResourceName);
                            }

                            if (!string.IsNullOrWhiteSpace(RESOURCE_NAME))
                            {
                                specificResourceName = RESOURCE_NAME;
                            }

                            var task = GenerateTaskDescription(taskId, WF_ID, specificResourceName);
                            executor.DefineTask(task);
                            executor.Execute(new[] { task.TaskId });
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Thread.Sleep(5000);
                    }
                });

                Thread.Sleep(GetNextRandom(
                                 TIME_BETWEEN_LAUNCHES.First(),
                                 TIME_BETWEEN_LAUNCHES.Last()
                                 ));
            }
        }
Пример #4
0
        static void WatchTasks()
        {
            using (var executor = new Executor.ExecutionBrokerServiceClient())
            {
                var timeStarted = DateTime.Now;
                Console.WriteLine("Started at {0}.", timeStarted);

                int finishedTasksCount = 0;
                while (finishedTasksCount < LAUNCHES_COUNT)
                {
                    var stateCounts = GetTaskStatesCount(WF_ID);
                    finishedTasksCount = stateCounts.Where(s =>
                                                           s.Key == Executor.TaskState.Completed ||
                                                           s.Key == Executor.TaskState.Failed ||
                                                           s.Key == Executor.TaskState.Aborted
                                                           ).Sum(s => s.Value);

                    double avgSecondsOnTask =
                        (DateTime.Now - timeStarted).TotalSeconds / ((finishedTasksCount == 0) ? 1 : finishedTasksCount);

                    Console.Write("{0}, ~{1} sec/task: ", DateTime.Now.ToString("HH:mm:ss"), avgSecondsOnTask);
                    foreach (var state in stateCounts.Keys)
                    {
                        Console.Write("{0} = {1} ", state, stateCounts[state]);
                    }
                    Console.WriteLine();

                    // todo : write to title

                    // todo : Fail reason (now only in event)

                    Thread.Sleep(GetNextRandom(
                                     TIME_BETWEEN_CHECKS.First(),
                                     TIME_BETWEEN_CHECKS.Last()
                                     ));
                }
            }

            Console.WriteLine("Finished");
            Console.ReadLine();
        }