Esempio n. 1
0
        private static WorkerConf CreateTestConf()
        {
            WorkerConf conf = new WorkerConf();

            conf.Name = "Test_".RandomLetters(4);
            return(conf);
        }
Esempio n. 2
0
        public void BuildConfShouldSave()
        {
            WorkerConf conf = CreateTestConf();

            conf.Save();
            string fileName = "./{0}_WorkerConf.json"._Format(conf.Name);

            Expect.IsTrue(File.Exists(fileName));
            File.Delete(fileName);
        }
Esempio n. 3
0
        public void WhenWorkerConfSavesShouldSetWorkerTypeName()
        {
            string filePath = "{0}.json"._Format(MethodBase.GetCurrentMethod().Name);
            AllProjectsBuildWorker worker = new AllProjectsBuildWorker("monkey");

            worker.SaveConf(filePath);
            WorkerConf conf = WorkerConf.Load(filePath);

            Expect.IsNotNull(conf.WorkerTypeName);
            Expect.AreEqual(typeof(AllProjectsBuildWorker).AssemblyQualifiedName, conf.WorkerTypeName);
        }
Esempio n. 4
0
 public ISheduler CreateSheduler(ILogger logger, WorkerConf workerConf)
 {
     if (workerConf.Shedule.StartTimes.Count > 0)
     {
         return(new ShedulerOnTime(logger, workerConf));
     }
     else if (workerConf.Shedule.RepeatTimeSpanMinutes > 0)
     {
         return(new ShedulerSequential(logger, workerConf));
     }
     else
     {
         return(new ShedulerBase(logger, workerConf));
     }
 }
Esempio n. 5
0
 public override void Run(Action <string> output = null, Action <string> error = null)
 {
     try
     {
         JobProviderArguments providerArguments = GetProviderArguments(true, true) as JobProviderArguments;
         JobConf    jobConf = GetJobConf(providerArguments.JobName);
         WorkerConf worker  = jobConf.GetWorkerConf(providerArguments.WorkerName);
         WorkState  result  = worker.CreateWorker(null).Do();
         OutLine(result.ToYaml(), ConsoleColor.Yellow);
         Exit(0);
     }
     catch (Exception ex)
     {
         Message.PrintLine("error running worker: {0}", ConsoleColor.Magenta, ex.Message);
         Exit(1);
     }
 }
Esempio n. 6
0
        public ShedulerBase(ILogger logger, WorkerConf workerConf)
        {
            _logger      = logger;
            _workerConf  = workerConf;
            _cancelToken = new CancellationTokenSource();

            // some checks
            if (_logger == null)
            {
                throw new Exception("Module 'ShedulerOnTime': constructor not get logger object.");
            }
            if (_workerConf == null)
            {
                _logger.LogWarning($"Not pass '{nameof(WorkerConf)}' object to module 'ShedulerOnTime'");
                return;
            }

            if (_workerConf.Shedule.IsStartAfterAppRun)
            {
                RunTask();
            }
        }
Esempio n. 7
0
 public override void Remove(Action <string> output = null, Action <string> error = null)
 {
     try
     {
         JobProviderArguments providerArguments = GetProviderArguments(true, true) as JobProviderArguments;
         JobConf    jobConf = GetJobConf(providerArguments.JobName);
         WorkerConf worker  = jobConf.GetWorkerConf(providerArguments.WorkerName);
         if (worker == null)
         {
             Message.PrintLine("Specified worker {0} was not a part of the specified job {1}", providerArguments.WorkerName, providerArguments.JobName);
             Exit(1);
         }
         jobConf.RemoveWorker(providerArguments.WorkerName);
         Message.PrintLine("Removed worker {0}", ConsoleColor.Yellow, providerArguments.WorkerName);
         Exit(0);
     }
     catch (Exception ex)
     {
         Message.PrintLine("error removing worker: {0}", ConsoleColor.Magenta, ex.Message);
         Exit(1);
     }
 }
Esempio n. 8
0
        public override void Edit(Action <string> output = null, Action <string> error = null)
        {
            try
            {
                JobProviderArguments providerArguments = GetProviderArguments(true, true) as JobProviderArguments;
                JobConf    jobConf    = GetJobConf(providerArguments.JobName);
                WorkerConf workerConf = jobConf.GetWorkerConf(providerArguments.WorkerName, true);
                if (workerConf == null)
                {
                    Message.PrintLine("specified worker was not found: {0}", providerArguments.WorkerName);
                    Exit(1);
                }

                ProcessOutput processOutput = ShellSettings.Current.Editor.Start(workerConf.LoadedFrom);
                jobConf.Save();
                Exit(0);
            }
            catch (Exception ex)
            {
                Message.PrintLine("error editing worker: {0}", ConsoleColor.Magenta, ex.Message);
                Exit(1);
            }
        }
Esempio n. 9
0
        public override void Show(Action <string> output = null, Action <string> error = null)
        {
            try
            {
                JobProviderArguments providerArguments = GetProviderArguments(false, true) as JobProviderArguments;
                JobConf jobConf = GetJobConf(providerArguments.JobName);
                if (!string.IsNullOrEmpty(providerArguments.WorkerName))
                {
                    WorkerConf workerConf = jobConf.GetWorkerConf(providerArguments.WorkerName);
                    if (workerConf == null)
                    {
                        Message.PrintLine("Specified worker {0} was not a part of the specified job {1}", providerArguments.WorkerName, providerArguments.JobName);
                        Exit(1);
                    }
                    string serialized = Serialize(workerConf);
                    Message.PrintLine("***\r\n{0}\r\n***", ConsoleColor.Blue, serialized);
                }
                else
                {
                    jobConf.ReloadWorkers();
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (string key in jobConf.WorkerConfs.Keys)
                    {
                        stringBuilder.AppendLine(key);
                        stringBuilder.AppendLine(Serialize(jobConf.WorkerConfs[key]));
                    }
                    Message.PrintLine("***\r\n{0}\r\n***", stringBuilder.ToString());
                }

                Exit(0);
            }
            catch (Exception ex)
            {
                Message.PrintLine("error showing worker: {0}", ConsoleColor.Magenta, ex.Message);
                Exit(1);
            }
        }
Esempio n. 10
0
 public ShedulerSequential(ILogger logger, WorkerConf workerConf) : base(logger, workerConf)
 {
     createTimer(timerCallback, _workerConf.Shedule.RepeatTimeSpanMinutes * 60 * 1000);
 }
Esempio n. 11
0
 public ShedulerOnTime(ILogger logger, WorkerConf workerConf) : base(logger, workerConf)
 {
     // each second check start time
     createTimer(timerCallback, 1000);
 }