Exemple #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);
        }
Exemple #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();
 }
Exemple #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}");
        }
        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);
        }
Exemple #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");
        }