Exemplo n.º 1
0
        public VMScriptJob GetQueuedScriptedJob(ScriptLanguageEnum languages)
        {
            var job = GetQueuedJob(languages);

            if (job == null)
            {
                return(null);
            }
            var         body        = GetScript(job);
            var         parameters  = GetJobParameters(job);
            VMScriptJob vmScriptJob = new VMScriptJob();

            vmScriptJob.Job        = job;
            vmScriptJob.Script     = body;
            vmScriptJob.Parameters = parameters;
            return(vmScriptJob);
        }
Exemplo n.º 2
0
 protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 {
     while (!stoppingToken.IsCancellationRequested)
     {
         string      url    = _automationHelper.GetUrl() + $"/api/Job/Queued?language={ScriptLanguageEnum.PowerShellCore}";
         VMScriptJob newJob = null;
         try
         {
             newJob = _automationHelper.GetWebCall <VMScriptJob>(url);
         }
         catch (Exception e)
         {
             if (null != e.InnerException)
             {
                 if (e.InnerException.Message.Equals("No connection could be made because the target machine actively refused it."))
                 {
                     _logger.LogError("Something went wrong trying to get queued job.");
                 }
             }
             else
             {
                 _logger.LogInformation("Server is offline");
             }
         }
         if (newJob != null)
         {
             PoshJob job = new PoshJob();
             job.JobUID = newJob.Job.JobUid;
             job.Script = newJob.Script;
             if (newJob.Parameters != null)
             {
                 job.Parameters = newJob.Parameters;
             }
             if (job.Script != null)
             {
                 _poshJobManager.QueuePendingJob(job);
             }
             else
             {
                 _logger.LogWarning("No script version found.");
             }
         }
         await Task.Delay(_automationHelper.GetGetQueuedJobDelay(), stoppingToken);
     }
 }