private JobList <FetchedJobDto> FetchedJobs(
            StatelessSessionWrapper session,
            IEnumerable <long> jobIds)
        {
            var list = jobIds.ToList();

            if (list.Any())
            {
                var result = new List <KeyValuePair <string, FetchedJobDto> >();

                foreach (var job in session.Query <_Job>().Where(i => list.Contains(i.Id)))
                {
                    result.Add(new KeyValuePair <string, FetchedJobDto>(
                                   job.Id.ToString(),
                                   new FetchedJobDto
                    {
                        Job   = DeserializeJob(job.InvocationData, job.Arguments),
                        State = job.StateName
                    }));
                }

                return(new JobList <FetchedJobDto>(result));
            }

            return(new JobList <FetchedJobDto>(new List <KeyValuePair <string, FetchedJobDto> >()));
        }
        private Dictionary <DateTime, long> GetTimelineStats(StatelessSessionWrapper session,
                                                             IDictionary <string, DateTime> keyMaps)
        {
            var valuesMap = session.Query <_AggregatedCounter>()
                            .Where(i => keyMaps.Keys.Contains(i.Key))
                            .ToDictionary(x => x.Key, x => x.Value);

            foreach (var key in keyMaps.Keys)
            {
                if (!valuesMap.ContainsKey(key))
                {
                    valuesMap.Add(key, 0);
                }
            }

            var result = new Dictionary <DateTime, long>();

            for (var i = 0; i < keyMaps.Count; i++)
            {
                var value = valuesMap[keyMaps.ElementAt(i).Key];
                result.Add(keyMaps.ElementAt(i).Value, value);
            }

            return(result);
        }
        private long GetNumberOfJobsByStateName(StatelessSessionWrapper session, string stateName)
        {
            var count        = session.Query <_Job>().Count(i => i.StateName == stateName);
            var jobListLimit = _storage.Options.DashboardJobListLimit;

            if (jobListLimit.HasValue)
            {
                return(Math.Min(count, jobListLimit.Value));
            }

            return(count);
        }
        private JobList <TDto> GetJobs <TDto>(
            StatelessSessionWrapper session,
            int from,
            int count,
            string stateName,
            Func <_Job, Job, Dictionary <string, string>, TDto> selector)
        {
            var jobs = session.Query <_Job>()
                       .OrderByDescending(i => i.Id)
                       .Where(i => i.StateName == stateName)
                       .Skip(from)
                       .Take(count)
                       .ToList();

            return(DeserializeJobs(jobs, selector));
        }
        public void Enqueue(StatelessSessionWrapper session, string queue, string jobId)
        {
            var converter = StringToInt32Converter.Convert(jobId);

            if (!converter.Valid)
            {
                return;
            }

            session.Insert(new _JobQueue
            {
                Job   = session.Query <_Job>().SingleOrDefault(i => i.Id == converter.Value),
                Queue = queue
            });

            Logger.DebugFormat("Enqueued JobId={0} Queue={1}", jobId, queue);
        }
        private JobList <EnqueuedJobDto> EnqueuedJobs(
            StatelessSessionWrapper session,
            IEnumerable <long> jobIds)
        {
            var list = jobIds.ToList();

            if (list.Any())
            {
                var jobs = session.Query <_Job>().Where(i => list.Contains(i.Id)).ToList();

                return(DeserializeJobs(
                           jobs,
                           (sqlJob, job, stateData) => new EnqueuedJobDto
                {
                    Job = job,
                    State = sqlJob.StateName,
                    EnqueuedAt = sqlJob.StateName == EnqueuedState.StateName
                            ? JobHelper.DeserializeNullableDateTime(stateData["EnqueuedAt"])
                            : null
                }));
            }

            return(new JobList <EnqueuedJobDto>(new List <KeyValuePair <string, EnqueuedJobDto> >()));
        }
Пример #7
0
 private static _Job GetTestJob(StatelessSessionWrapper connection, string jobId)
 {
     return(connection.Query <_Job>().Single(i => i.Id == long.Parse(jobId)));
 }
        private static bool IsEntryExpired(StatelessSessionWrapper session, long entryId)
        {
            var count = session.Query <_AggregatedCounter>().Count(i => i.Id == entryId);

            return(count == 0);
        }