Esempio n. 1
0
        ///<summary>
        ///Obtiene las tareas recurrentes de un repositorio
        ///</summary>
        ///<param name="repositoryID">Identificador del repositorio</param>
        ///<returns>Lista de tareas recurrentes</returns>
        public List <RecurringJobViewModel> GetRecurringJobs(Guid repositoryID)
        {
            List <string> recurringJobsId = _context.JobRepository.Where(item => item.IdRepository.Equals(repositoryID) && item.FechaEjecucion < DateTime.Now && item.IdJob.Contains("_")).Select(item => item.IdJob).ToList();
            List <RecurringJobViewModel> recurringJobs = new List <RecurringJobViewModel>();

            foreach (string id in recurringJobsId)
            {
                if (id.Contains("_"))
                {
                    var    parts = id.Split("_");
                    string jobID = parts[1];
                    if (parts.Length > 2)
                    {
                        var correct = CrontabSchedule.TryParse(parts[parts.Length - 1]);
                        if (correct != null)
                        {
                            int partsNum = parts.Length;
                            for (int i = 1; i < partsNum - 1; i++)
                            {
                                if (i == 1)
                                {
                                    jobID = $"{parts[i]}";
                                }
                                else
                                {
                                    jobID = $"{jobID}_{parts[i]}";
                                }
                            }
                        }
                        else
                        {
                            int partsNum = parts.Length;
                            for (int i = 1; i < partsNum; i++)
                            {
                                if (i == 1)
                                {
                                    jobID = $"{parts[i]}";
                                }
                                else
                                {
                                    jobID = $"{jobID}_{parts[i]}";
                                }
                            }
                        }
                    }
                    var recurringJob = _cronApiService.GetRecurringJobs(jobID);
                    if (recurringJob != null)
                    {
                        recurringJobs.Add(recurringJob);
                    }
                }
            }
            return(recurringJobs);
        }
 public IActionResult GetRecurringJob()
 {
     return(Ok(_cronApiService.GetRecurringJobs()));
 }