Beispiel #1
0
        public void Execute(CancellationToken cancellationToken)
        {
            Logger.DebugFormat("Aggregating records in 'Counter' table...");

            var removedCount = 0;

            do
            {
                _storage.UseConnection(connection =>
                {
                    removedCount = connection.Execute(GetMergeQuery(), new { COUNT = NumberOfRecordsInSinglePass });
                });

                if (removedCount >= NumberOfRecordsInSinglePass)
                {
                    cancellationToken.WaitHandle.WaitOne(DelayBetweenPasses);
                    cancellationToken.ThrowIfCancellationRequested();
                }
            } while (removedCount >= NumberOfRecordsInSinglePass);

            cancellationToken.WaitHandle.WaitOne(_interval);
        }
        public override string CreateExpiredJob(Job job, IDictionary <string, string> parameters, DateTime createdAt, TimeSpan expireIn)
        {
            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var invocationData = InvocationData.SerializeJob(job);

            invocationData.Arguments = null;
            var arguments = InvocationData.SerializeJob(job);

            Logger.TraceFormat("CreateExpiredJob={0}", SerializationHelper.Serialize(invocationData, SerializationOption.User));

            return(_storage.UseConnection(connection =>
            {
                var jobId = connection.GetNextJobId();

                var oracleDynamicParameters = new OracleDynamicParameters();
                oracleDynamicParameters.AddDynamicParams(new
                {
                    ID = jobId,
                    CREATED_AT = createdAt,
                    EXPIRE_AT = createdAt.Add(expireIn)
                });
                oracleDynamicParameters.Add("INVOCATION_DATA", SerializationHelper.Serialize(invocationData, SerializationOption.User), OracleMappingType.NClob, ParameterDirection.Input);
                oracleDynamicParameters.Add("ARGUMENTS", arguments.Arguments, OracleMappingType.NClob, ParameterDirection.Input);

                connection.Execute(
                    @" 
 INSERT INTO HF_JOB (ID, INVOCATION_DATA, ARGUMENTS, CREATED_AT, EXPIRE_AT) 
      VALUES (:ID, :INVOCATION_DATA, :ARGUMENTS, :CREATED_AT, :EXPIRE_AT)
",
                    oracleDynamicParameters);

                if (parameters.Count > 0)
                {
                    var parameterArray = new object[parameters.Count];
                    var parameterIndex = 0;
                    foreach (var parameter in parameters)
                    {
                        var dynamicParameters = new OracleDynamicParameters();
                        dynamicParameters.AddDynamicParams(new
                        {
                            JOB_ID = jobId,
                            NAME = parameter.Key
                        });
                        dynamicParameters.Add("VALUE", parameter.Value, OracleMappingType.NClob, ParameterDirection.Input);

                        parameterArray[parameterIndex++] = dynamicParameters;
                    }

                    connection.Execute(@"INSERT INTO HF_JOB_PARAMETER (ID, NAME, VALUE, JOB_ID) VALUES (HF_SEQUENCE.NEXTVAL, :NAME, :VALUE, :JOB_ID)", parameterArray);
                }

                return jobId.ToString();
            }));
        }