public DT.TaskPage GetTasksByJobId(Guid id, int page, int size, IEnumerable <string> states)
        {
            var pm           = PersistenceManager;
            var dimJobDao    = pm.DimJobDao;
            var dimClientDao = pm.DimClientDao;
            var factTaskDao  = pm.FactTaskDao;

            DA.DimJob job = pm.UseTransaction(() => dimJobDao.GetById(id));
            if (job == null)
            {
                throw new ArgumentException("invalid job id");
            }
            if (job.UserId != UserManager.CurrentUserId)
            {
                RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator);
            }

            return(pm.UseTransaction(() => {
                var tasks = factTaskDao.GetByJobId(id).Where(x => states.Contains(x.TaskState.ToString()));
                return new DT.TaskPage {
                    TotalTasks = tasks.Count(),
                    Tasks = (from factTask in tasks
                             join dimJob in dimJobDao.GetAll() on factTask.JobId equals dimJob.JobId
                             join dimClient in dimClientDao.GetAll() on factTask.LastClientId equals
                             dimClient.Id into taskClientJoin
                             from a in taskClientJoin.DefaultIfEmpty()
                             let startTime = factTask.StartTime ?? DateTime.Now
                                             let endTime = factTask.EndTime ?? DateTime.Now
                                                           select new DT.Task {
                        Id = factTask.TaskId,
                        JobId = factTask.JobId,
                        JobName = dimJob.JobName,
                        TotalTime = (long)(endTime - startTime).TotalSeconds,
                        CalculatingTime = factTask.CalculatingTime,
                        WaitingTime = factTask.WaitingTime,
                        TransferTime = factTask.TransferTime,
                        InitialWaitingTime = factTask.InitialWaitingTime,
                        NumCalculationRuns = factTask.NumCalculationRuns,
                        NumRetries = factTask.NumRetries,
                        CoresRequired = factTask.CoresRequired,
                        MemoryRequired = factTask.MemoryRequired,
                        Priority = factTask.Priority,
                        State = factTask.TaskState.ToString(),
                        LastClientId = factTask.LastClientId,
                        LastClientName = a != null ? a.Name : string.Empty,
                        UserId = dimJob.UserId,
                        UserName = dimJob.UserName,
                        StartTime = factTask.StartTime,
                        EndTime = factTask.EndTime,
                        Exception = factTask.Exception
                    })
                            .Skip((page - 1) * size)
                            .Take(size)
                            .ToList()
                };
            }));
        }
Exemplo n.º 2
0
 private DT.Job ConvertToDT(DA.DimJob job)
 {
     return(new DT.Job {
         Id = job.JobId,
         Name = job.JobName,
         UserId = job.UserId,
         UserName = job.UserName,
         DateCreated = job.DateCreated,
         DateCompleted = job.DateCompleted,
         TotalTasks = job.TotalTasks,
         CompletedTasks = job.CompletedTasks
     });
 }
 partial void UpdateDimJob(DimJob instance);
 partial void DeleteDimJob(DimJob instance);
 partial void InsertDimJob(DimJob instance);