コード例 #1
0
        public async Task <object> RetryParticipationSyncImmediately(
            CrmData data,
            Configurations requestWideSettings,
            bool requestConsumerId = false)
        {
            var jobId = await Task.Run(() => BackgroundJob.Enqueue <ICrmConsumerProvider>(
                                           iCrmProvider =>
                                           iCrmProvider.CreateParticipationAsync(
                                               data,
                                               requestWideSettings,
                                               requestConsumerId)));

            var             result        = new object();
            IMonitoringApi  monitoringApi = JobStorage.Current.GetMonitoringApi();
            JobDetailsDto   jobDetails    = monitoringApi.JobDetails(jobId);
            SucceededJobDto jobDto        = monitoringApi.SucceededJobs(0, int.MaxValue)
                                            .First()
                                            //.FirstOrDefault(job => job.Key == "Key")
                                            .Value;

            if (jobDto != null)
            {
                result = jobDto.Result;
                return(JsonConvert.DeserializeObject <CrmResponse>(result.ToString()));
            }

            return(null);
        }
コード例 #2
0
 public void Refresh()
 {
     _scheduled  = _hangfire.ScheduledJobs(0, (int)_hangfire.ScheduledCount());
     _processing = _hangfire.ProcessingJobs(0, (int)_hangfire.ProcessingCount());
     _failed     = _hangfire.FailedJobs(0, (int)_hangfire.FailedCount());
     _succeded   = _hangfire.SucceededJobs(0, (int)_hangfire.SucceededListCount());
     _recurring  = JobStorage.Current.GetConnection().GetRecurringJobs();
 }
コード例 #3
0
        private void AppendAverageJobDuration(StringBuilder data)
        {
            data.AppendLine("# Help Average Total Duration");
            double average = api.SucceededJobs(0, int.MaxValue)
                             .Select(job => job.Value.TotalDuration)
                             .Average() ?? 0;

            data.AppendLine($"hangfire_average_total_duration {average}");
        }
コード例 #4
0
        private HangfireJob CreateJobCache()
        {
            if (_jobCache.HasJobs)
            {
                return(_jobCache);
            }
            //else

            _monitor.EnqueuedJobs("default", 0, int.MaxValue).Select(x => x.Value)
            .ForEach(x => _jobCache.AddJob(x, HangfireJob.QUEUED));
            _monitor.ScheduledJobs(0, int.MaxValue).Select(x => x.Value)
            .ForEach(x => _jobCache.AddJob(x, HangfireJob.QUEUED));
            _monitor.FailedJobs(0, int.MaxValue).Select(x => x.Value)
            .ForEach(x => _jobCache.AddJob(x, HangfireJob.FAILED));
            _monitor.SucceededJobs(0, int.MaxValue).Select(x => x.Value)
            .ForEach(x => _jobCache.AddJob(x, HangfireJob.SUCCEEDED));
            _monitor.ProcessingJobs(0, int.MaxValue).Select(x => x.Value)
            .ForEach(x => _jobCache.AddJob(x, HangfireJob.PROCESSING));
            return(_jobCache);
        }
コード例 #5
0
        private TResult GetResult <TResult>(string jobId)
        {
            var total = (int)monitoringApi.SucceededListCount();

            var numberOfJobs = 10;

            for (var i = 0; i < total; i += numberOfJobs)
            {
                var start = Math.Max(total - i - numberOfJobs, 0);
                var end   = total - i;
                var count = end - start;
                var job   = monitoringApi.SucceededJobs(start, count).SingleOrDefault(x => x.Key == jobId).Value;
                if (job != null)
                {
                    var result = job.Result;
                    if (result.GetType() == typeof(string))
                    {
                        return(JsonConvert.DeserializeObject <TResult>((string)result));
                    }
                    return((TResult)job.Result);
                }
            }
            throw new InvalidOperationException("Failed to find job");
        }