예제 #1
0
        /// <summary>
        /// Queues a VSS job to be run by hangfire in the background
        /// </summary>
        public string QueueHangfireJob(JobRequest request, IJobCallback onContinuation = null, string continuationJobname = "Default continuation job")
        {
            // We have to pass in a null PerformContext, as Hangfire will inject the correct one when the job is run.

            var client = new BackgroundJobClient();
            var state  = new EnqueuedState(jobManager.GetQueueName(request.JobUid));

            //TODO: Ugly code but can't figure out a better way with Hangfire as can't apply dynamic filters on methods in a singleton context
            var parentJob = string.Empty;

            if (request.AttributeFilters == SpecialFilters.ExportFilter)
            {
                parentJob = client.Create(() => RunHangfireJobExportFilter(jobManager.GetJobName(request.JobUid), request, false, null, null), state);
                if (onContinuation != null)
                {
                    JobStorage.Current.GetConnection().SetJobParameter(parentJob, Tags.CONTINUATION_TYPE, onContinuation.GetType().FullName);
                    return(client.ContinueJobWith(parentJob, () => RunHangfireJobExportFilter(
                                                      onContinuation.GetType().Name,
                                                      null,
                                                      true,
                                                      parentJob,
                                                      null), nextState: state, options: JobContinuationOptions.OnAnyFinishedState));
                }
            }
            else
            {
                parentJob = client.Create(() => RunHangfireJob(jobManager.GetJobName(request.JobUid), request, false, null, null), state);
                if (onContinuation != null)
                {
                    JobStorage.Current.GetConnection().SetJobParameter(parentJob, Tags.CONTINUATION_TYPE, onContinuation.GetType().FullName);
                    return(client.ContinueJobWith(parentJob, () => RunHangfireJob(
                                                      onContinuation.GetType().Name,
                                                      null,
                                                      true,
                                                      parentJob,
                                                      null), nextState: state, options: JobContinuationOptions.OnAnyFinishedState));
                }
            }
            return(parentJob);
        }