コード例 #1
0
ファイル: JobQueueClient.cs プロジェクト: Kiphaz/PureActive
 /// <summary>
 ///     Constructor.
 /// </summary>
 public JobQueueClient(
     IBackgroundJobClient backgroundJobClient,
     JobStorage jobStorage)
 {
     _backgroundJobClient = backgroundJobClient;
     _monitoringApi       = jobStorage.GetMonitoringApi();
 }
コード例 #2
0
 public JobManager(JobStorage jobStorage, IBackgroundJobClient backgroundJobClient, IPerformingContextAccessor performingContextAccessor, ILogger <JobManager> logger)
 {
     this.monitoringApi             = jobStorage.GetMonitoringApi();
     this.performingContextAccessor = performingContextAccessor;
     this.logger = logger;
     this.backgroundJobClient = backgroundJobClient;
 }
コード例 #3
0
 public ConfigurationState(
     StoredConfiguration configuration,
     Func <JobStorage> jobStorageCreator
     )
 {
     Configuration        = configuration;
     _jobStorage          = new Lazy <JobStorage>(jobStorageCreator, LazyThreadSafetyMode.ExecutionAndPublication);
     _backgroundJobClient = new Lazy <IBackgroundJobClient>(() => new BackgroundJobClient(JobStorage), LazyThreadSafetyMode.ExecutionAndPublication);
     _recurringJobManager = new Lazy <IRecurringJobManager>(() => new RecurringJobManager(JobStorage), LazyThreadSafetyMode.ExecutionAndPublication);
     _monitoringApi       = new Lazy <IMonitoringApi>(() => JobStorage.GetMonitoringApi(), LazyThreadSafetyMode.ExecutionAndPublication);
 }
コード例 #4
0
        public IMonitoringApi GetHangFireMonitoringApi()
        {
            if (_jobStorageCurrent == null)
            {
                InitializeHangFire();
            }

            if (_jobStorageCurrent != null)
            {
                _hangFireMonitoringApi = _jobStorageCurrent.GetMonitoringApi();
            }

            return(_hangFireMonitoringApi);
        }
コード例 #5
0
        public string CheckStatus()
        {
            try
            {
                var  servers = _jobStorage.GetMonitoringApi().Servers();
                bool queueIsBeingProcessed = servers.Any(
                    s => s.Queues.Contains("Default", StringComparer.InvariantCultureIgnoreCase));

                return(queueIsBeingProcessed ? HealthCheckResponse.StatusOk : "No workers are processing the Default queue!");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
コード例 #6
0
        public HangfireJobStatistics GetJobStatistics()
        {
            StatisticsDto hangfireStats = _hangfireJobStorage.GetMonitoringApi().GetStatistics();
            long          retryJobs     = _hangfireJobStorage.GetConnection().GetAllItemsFromSet(retrySetName).Count;

            return(new HangfireJobStatistics
            {
                Failed = hangfireStats.Failed,
                Enqueued = hangfireStats.Enqueued,
                Scheduled = hangfireStats.Scheduled,
                Processing = hangfireStats.Processing,
                Succeeded = hangfireStats.Succeeded,
                Retry = retryJobs
            });
        }
コード例 #7
0
        public static IEnumerable <KeyValuePair <string, ScheduledJobDto> > EnumerateScheduledJobs <TJob, TJobModel>(this JobStorage storage, Func <TJobModel, bool> predicate)
        {
            var       api  = storage.GetMonitoringApi();
            var       skip = 0;
            const int take = 100;
            JobList <ScheduledJobDto> jobList;

            do
            {
                jobList = api.ScheduledJobs(skip, take);

                var jobs = jobList.FindAll(x => x.Value.Job.Type == typeof(TJob));
                foreach (var job in jobs.Where(x => predicate((TJobModel)x.Value.Job.Args[0])))
                {
                    yield return(job);
                }

                skip += take;
            } while (jobList.Count == take);
        }
コード例 #8
0
        public PostgreSqlTagsMonitoringApi(JobStorage postgreSqlStorage)
        {
            var monitoringApi = postgreSqlStorage.GetMonitoringApi();

            if (monitoringApi.GetType().Name != "PostgreSqlMonitoringApi")
            {
                throw new ArgumentException("The monitor API is not implemented using PostgreSql", nameof(monitoringApi));
            }

            _monitoringApi     = monitoringApi;
            _postgreSqlStorage = postgreSqlStorage;

            // Other transaction type, clear cached methods
            if (_type != monitoringApi.GetType())
            {
                _useConnection = null;

                _type = monitoringApi.GetType();
            }

            if (_useConnection == null)
            {
                _useConnection = monitoringApi.GetType().GetTypeInfo().GetMethod(nameof(UseConnection),
                                                                                 BindingFlags.NonPublic | BindingFlags.Instance);
            }

            if (_useConnection == null)
            {
                _useConnection = postgreSqlStorage.GetType().GetTypeInfo().GetMethod(nameof(UseConnection),
                                                                                     BindingFlags.NonPublic | BindingFlags.Instance);
                _useStorage = true;
            }

            if (_useConnection == null)
            {
                throw new ArgumentException("The function UseConnection cannot be found.");
            }
        }
 public ApplicationInsightsTelemetryBackgroundService(TelemetryClient telemetryClient, JobStorage hangfireJobStorage, ILogger <ApplicationInsightsTelemetryBackgroundService> logger)
 {
     _telemetryClient = telemetryClient;
     _hangfireApi     = hangfireJobStorage.GetMonitoringApi();
     _logger          = logger;
 }
コード例 #10
0
 private MySqlTagsMonitoringApi GetMonitoringApi(JobStorage jobStorage)
 {
     return(new MySqlTagsMonitoringApi(jobStorage.GetMonitoringApi()));
 }
コード例 #11
0
        public string ResumeJob(IDSFDataObject dsfDataObject, string jobId, bool overrideVariables, string environment)
        {
            try
            {
                var monitoringApi = _jobStorage.GetMonitoringApi();
                var jobDetails    = monitoringApi.JobDetails(jobId);
                var currentState  = jobDetails.History.OrderBy(s => s.CreatedAt).LastOrDefault();

                if (currentState?.StateName != "Scheduled" && currentState?.StateName != "Failed")
                {
                    return(GlobalConstants.Failed);
                }

                var values = jobDetails.Job.Args[0] as Dictionary <string, StringBuilder>;
                values.TryGetValue("environment", out StringBuilder persistedEnvironment);
                var decryptEnvironment = persistedEnvironment.ToString().CanBeDecrypted() ? DpapiWrapper.Decrypt(persistedEnvironment.ToString()) : persistedEnvironment.ToString();
                if (overrideVariables)
                {
                    if (values.ContainsKey("environment"))
                    {
                        values["environment"] = new StringBuilder(environment);
                    }
                }
                else
                {
                    values["environment"] = new StringBuilder(decryptEnvironment);
                }
                values.TryGetValue("currentuserprincipal", out StringBuilder currentUserPrincipal);
                var decryptCurrentUserPrincipal = currentUserPrincipal.ToString().CanBeDecrypted() ? DpapiWrapper.Decrypt(currentUserPrincipal.ToString()) : currentUserPrincipal.ToString();
                if (values.ContainsKey("environment"))
                {
                    values["currentuserprincipal"] = new StringBuilder(decryptCurrentUserPrincipal);
                }
                var workflowResume = new WorkflowResume();
                var result         = workflowResume.Execute(values, null);
                var serializer     = new Dev2JsonSerializer();
                var executeMessage = serializer.Deserialize <ExecuteMessage>(result);
                if (executeMessage.HasError)
                {
                    var failedState = new FailedState(new Exception(executeMessage.Message?.ToString()));
                    _client.ChangeState(jobId, failedState, ScheduledState.StateName);
                    return(GlobalConstants.Failed);
                }

                values.TryGetValue("resourceID", out StringBuilder workflowId);
                values.TryGetValue("environment", out StringBuilder environments);
                values.TryGetValue("startActivityId", out StringBuilder startActivityId);
                values.TryGetValue("versionNumber", out StringBuilder versionNumber);
                values.TryGetValue("currentprincipal", out StringBuilder currentprincipal);

                _stateNotifier = dsfDataObject.StateNotifier;
                var audit = new Audit
                {
                    WorkflowID     = workflowId?.ToString(),
                    Environment    = environments?.ToString(),
                    VersionNumber  = versionNumber?.ToString(),
                    NextActivityId = startActivityId?.ToString(),
                    AuditDate      = DateTime.Now,
                    AuditType      = "LogResumeExecutionState",
                    LogLevel       = LogLevel.Info,
                    User           = currentprincipal?.ToString()
                };

                _stateNotifier?.LogAdditionalDetail(audit, nameof(ResumeJob));
                var manuallyResumedState = new ManuallyResumedState(environments?.ToString());

                _client.ChangeState(jobId, manuallyResumedState, currentState?.StateName);
                return(GlobalConstants.Success);
            }
            catch (Exception ex)
            {
                _stateNotifier?.LogExecuteException(ex, this);
                Dev2Logger.Error(nameof(ResumeJob), ex, GlobalConstants.WarewolfError);
                throw new Exception(ex.Message);
            }
        }
コード例 #12
0
 private static SqlTagsMonitoringApi GetMonitoringApi(JobStorage jobStorage)
 {
     return(new SqlTagsMonitoringApi(jobStorage.GetMonitoringApi()));
 }
コード例 #13
0
 internal RedisTagsMonitoringApi GetMonitoringApi(JobStorage jobStorage)
 {
     return(new RedisTagsMonitoringApi(jobStorage.GetMonitoringApi(), _options));
 }
コード例 #14
0
		private void TryScheduleJob(
			JobStorage storage,
			IStorageConnection connection, 
			string recurringJobId, 
			IReadOnlyDictionary<string, string> recurringJob)
		{
			var serializedJob = JobHelper.FromJson<InvocationData>(recurringJob["Job"]);
			var job = serializedJob.Deserialize();
			var cron = recurringJob["Cron"];
			var cronSchedule = CrontabSchedule.Parse(cron);

			try
			{
				var timeZone = recurringJob.ContainsKey("TimeZoneId")
					? TimeZoneInfo.FindSystemTimeZoneById(recurringJob["TimeZoneId"])
					: TimeZoneInfo.Utc;

				var instant = _instantFactory(cronSchedule, timeZone);

				var lastExecutionTime = recurringJob.ContainsKey("LastExecution")
					? JobHelper.DeserializeDateTime(recurringJob["LastExecution"])
					: (DateTime?)null;

				var changedFields = new Dictionary<string, string>();

				const string lastJobId = "LastJobId";
				if (recurringJob.ContainsKey(lastJobId) && !string.IsNullOrWhiteSpace(recurringJob[lastJobId]))
				{
					var jobDetails = storage.GetMonitoringApi().JobDetails(recurringJob[lastJobId]);
					var finalStates = new[] {"Succeeded", "Deleted"};
					if (!jobDetails.History.Select(x => x.StateName).Any(finalStates.Contains))
					{
						Logger.Info("The recurring task " + recurringJobId + " is still running, do not schedule it more. ");
						return;
					}
				}

				if (instant.GetNextInstants(lastExecutionTime).Any())
				{

					var state = new EnqueuedState { Reason = "Triggered by recurring job scheduler" };
					if (recurringJob.ContainsKey("Queue") && !String.IsNullOrEmpty(recurringJob["Queue"]))
					{
						state.Queue = recurringJob["Queue"];
					}

					var backgroundJob = _factory.Create(new CreateContext(storage, connection, job, state));
					var jobId = backgroundJob != null ? backgroundJob.Id : null;

					if (String.IsNullOrEmpty(jobId))
					{
						Logger.DebugFormat(
							"Recurring job '{0}' execution at '{1}' has been canceled.",
							recurringJobId,
							instant.NowInstant);
					}

					changedFields.Add("LastExecution", JobHelper.SerializeDateTime(instant.NowInstant));
					changedFields.Add(lastJobId, jobId ?? String.Empty);
				}

				changedFields.Add("NextExecution", JobHelper.SerializeDateTime(instant.NextInstant));

				connection.SetRangeInHash(
					String.Format("recurring-job:{0}", recurringJobId),
					changedFields);
			}
			catch (TimeZoneNotFoundException ex)
			{
				Logger.ErrorException(
					String.Format("Recurring job '{0}' was not triggered: {1}.", recurringJobId, ex.Message),
					ex);
			}
		}
コード例 #15
0
 private SQLiteTagsMonitoringApi GetMonitoringApi(JobStorage jobStorage)
 {
     return(new SQLiteTagsMonitoringApi(jobStorage.GetMonitoringApi()));
 }