예제 #1
0
        /// <summary>
        /// Gets a collection of jobs that match the given filter parameters, ordered by the given sort parameters.
        /// </summary>
        /// <param name="likeName">A string representing a full or partial job name to filter on.</param>
        /// <param name="withStatus">A <see cref="JobStatus"/> to filter on, or null if not applicable.</param>
        /// <param name="inSchedule">A schedule name to filter on, if applicable.</param>
        /// <param name="orderBy">A field to order the resultset by.</param>
        /// <param name="sortDescending">A value indicating whether to order the resultset in descending order.</param>
        /// <param name="pageNumber">The page number to get.</param>
        /// <param name="pageSize">The size of the pages to get.</param>
        /// <param name="transaction">The transaction to execute the command in.</param>
        /// <returns>A collection of jobs.</returns>
        public override IEnumerable<JobRecord> GetJobs(string likeName, JobStatus? withStatus, string inSchedule, JobRecordResultsOrderBy orderBy, bool sortDescending, int pageNumber, int pageSize, IJobStoreTransaction transaction)
        {
            SqlJobStoreTransaction trans = transaction as SqlJobStoreTransaction;
            DbConnection connection = null;
            DbCommand command = null;
            List<JobRecord> records = new List<JobRecord>();

            try
            {
                if (trans != null)
                {
                    command = this.CreateSelectCommand(trans.Connection, likeName, withStatus, inSchedule, orderBy, sortDescending, pageNumber, pageSize);
                    command.Transaction = trans.Transaction;
                }
                else
                {
                    connection = this.CreateAndOpenConnection();
                    command = this.CreateSelectCommand(connection, likeName, withStatus, inSchedule, orderBy, sortDescending, pageNumber, pageSize);
                }

                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        records.Add(this.CreateRecord(reader));
                    }
                }
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }

                this.DisposeConnection(connection);
            }

            return records;
        }
예제 #2
0
        /// <summary>
        /// Saves the given job record, either creating it or updating it.
        /// </summary>
        /// <param name="record">The job to save.</param>
        /// <param name="transaction">The transaction to execute the command in.</param>
        public override void SaveJob(JobRecord record, IJobStoreTransaction transaction)
        {
            SqlJobStoreTransaction trans = transaction as SqlJobStoreTransaction;
            DbConnection connection = null;
            DbCommand command = null;
            bool creating = !record.Id.HasValue;

            try
            {
                if (trans != null)
                {
                    command = this.CreateSaveCommand(trans.Connection, record);
                    command.Transaction = trans.Transaction;
                }
                else
                {
                    connection = this.CreateAndOpenConnection();
                    command = this.CreateSaveCommand(connection, record);
                }

                if (creating)
                {
                    using (DbDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            record.Id = Convert.ToInt32(reader[0], CultureInfo.InvariantCulture);
                        }
                    }
                }
                else
                {
                    command.ExecuteNonQuery();
                }
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }

                this.DisposeConnection(connection);
            }
        }
예제 #3
0
        /// <summary>
        /// Gets the number of jobs in the store that match the given filter.
        /// </summary>
        /// <param name="likeName">A string representing a full or partial job name to filter on.</param>
        /// <param name="withStatus">A <see cref="JobStatus"/> to filter on, or null if not applicable.</param>
        /// <param name="inSchedule">A schedule name to filter on, if applicable.</param>
        /// <param name="transaction">The transaction to execute the command in.</param>
        /// <returns>The number of jobs that match the given filter.</returns>
        public override int GetJobCount(string likeName, JobStatus? withStatus, string inSchedule, IJobStoreTransaction transaction)
        {
            SqlJobStoreTransaction trans = transaction as SqlJobStoreTransaction;
            DbConnection connection = null;
            DbCommand command = null;
            int count = 0;

            try
            {
                if (trans != null)
                {
                    command = this.CreateCountCommand(trans.Connection, likeName, withStatus, inSchedule);
                    command.Transaction = trans.Transaction;
                }
                else
                {
                    connection = this.CreateAndOpenConnection();
                    command = this.CreateCountCommand(connection, likeName, withStatus, inSchedule);
                }

                count = Convert.ToInt32(command.ExecuteScalar(), CultureInfo.InvariantCulture);
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }

                this.DisposeConnection(connection);
            }

            return count;
        }
예제 #4
0
        /// <summary>
        /// Gets a collection of jobs with the given status, returning
        /// at most the number of jobs identified by <paramref name="count"/>.
        /// </summary>
        /// <param name="status">The status of the jobs to get.</param>
        /// <param name="count">The maximum number of jobs to get.</param>
        /// <param name="before">The queued-after date to filter on.</param>
        /// <param name="transaction">The transaction to execute the command in.</param>
        /// <returns>A collection of jobs.</returns>
        public override IEnumerable<JobRecord> GetJobs(JobStatus status, int count, DateTime before, IJobStoreTransaction transaction)
        {
            SqlJobStoreTransaction trans = transaction as SqlJobStoreTransaction;
            DbConnection connection = null;
            DbCommand command = null;
            List<JobRecord> records = new List<JobRecord>();

            try
            {
                if (trans != null)
                {
                    command = this.CreateSelectCommand(trans.Connection, status, count, before);
                    command.Transaction = trans.Transaction;
                }
                else
                {
                    connection = this.CreateAndOpenConnection();
                    command = this.CreateSelectCommand(connection, status, count, before);
                }

                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        records.Add(this.CreateRecord(reader));
                    }
                }
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }

                this.DisposeConnection(connection);
            }

            return records;
        }
예제 #5
0
        /// <summary>
        /// Deletes all jobs older than the given date.
        /// </summary>
        /// <param name="olderThan">The date to delete jobs older than.</param>
        /// <param name="transaction">The transaction to execute the command in.</param>
        public override void DeleteJobs(DateTime olderThan, IJobStoreTransaction transaction)
        {
            SqlJobStoreTransaction trans = transaction as SqlJobStoreTransaction;
            DbConnection connection = null;
            DbCommand command = null;

            try
            {
                if (trans != null)
                {
                    command = this.CreateDeleteCommand(trans.Connection, olderThan);
                    command.Transaction = trans.Transaction;
                }
                else
                {
                    connection = this.CreateAndOpenConnection();
                    command = this.CreateDeleteCommand(connection, olderThan);
                }

                command.ExecuteNonQuery();
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }

                this.DisposeConnection(connection);
            }
        }
예제 #6
0
        /// <summary>
        /// Gets a job by ID.
        /// </summary>
        /// <param name="id">The ID of the job to get.</param>
        /// <param name="transaction">The transaction to execute the command in.</param>
        /// <returns>The job with the given ID.</returns>
        public override JobRecord GetJob(int id, IJobStoreTransaction transaction)
        {
            SqlJobStoreTransaction trans = transaction as SqlJobStoreTransaction;
            DbConnection connection = null;
            DbCommand command = null;
            JobRecord record = null;

            try
            {
                if (trans != null)
                {
                    command = this.CreateSelectCommand(trans.Connection, id);
                    command.Transaction = trans.Transaction;
                }
                else
                {
                    connection = this.CreateAndOpenConnection();
                    command = this.CreateSelectCommand(connection, id);
                }

                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        record = this.CreateRecord(reader);
                    }
                }
            }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }

                this.DisposeConnection(connection);
            }

            return record;
        }
예제 #7
0
 /// <summary>
 /// Gets a collection of jobs that match the given filter parameters, ordered by the given sort parameters.
 /// </summary>
 /// <param name="likeName">A string representing a full or partial job name to filter on.</param>
 /// <param name="withStatus">A <see cref="JobStatus"/> to filter on, or null if not applicable.</param>
 /// <param name="inSchedule">A schedule name to filter on, if applicable.</param>
 /// <param name="orderBy">A field to order the resultset by.</param>
 /// <param name="sortDescending">A value indicating whether to order the resultset in descending order.</param>
 /// <param name="pageNumber">The page number to get.</param>
 /// <param name="pageSize">The size of the pages to get.</param>
 /// <param name="transaction">The transaction to execute the command in.</param>
 /// <returns>A collection of jobs.</returns>
 public abstract IEnumerable<JobRecord> GetJobs(string likeName, JobStatus? withStatus, string inSchedule, JobRecordResultsOrderBy orderBy, bool sortDescending, int pageNumber, int pageSize, IJobStoreTransaction transaction);
예제 #8
0
 /// <summary>
 /// Deletes a job by ID.
 /// </summary>
 /// <param name="id">The ID of the job to delete.</param>
 /// <param name="transaction">The transaction to execute the command in.</param>
 public abstract void DeleteJob(int id, IJobStoreTransaction transaction);
예제 #9
0
 /// <summary>
 /// Gets a collection of jobs that match the given collection of IDs.
 /// </summary>
 /// <param name="ids">The IDs of the jobs to get.</param>
 /// <param name="transaction">The transaction to execute the command in.</param>
 /// <returns>A collection of jobs.</returns>
 public abstract IEnumerable<JobRecord> GetJobs(IEnumerable<int> ids, IJobStoreTransaction transaction);
예제 #10
0
 /// <summary>
 /// Gets a collection of jobs with the given status, returning
 /// at most the number of jobs identified by <paramref name="count"/>.
 /// </summary>
 /// <param name="status">The status of the jobs to get.</param>
 /// <param name="count">The maximum number of jobs to get.</param>
 /// <param name="before">The queued-after date to filter on.</param>
 /// <param name="transaction">The transaction to execute the command in.</param>
 /// <returns>A collection of jobs.</returns>
 public abstract IEnumerable<JobRecord> GetJobs(JobStatus status, int count, DateTime before, IJobStoreTransaction transaction);
예제 #11
0
 /// <summary>
 /// Gets the number of jobs in the store that match the given filter.
 /// </summary>
 /// <param name="likeName">A string representing a full or partial job name to filter on.</param>
 /// <param name="withStatus">A <see cref="JobStatus"/> to filter on, or null if not applicable.</param>
 /// <param name="inSchedule">A schedule name to filter on, if applicable.</param>
 /// <param name="transaction">The transaction to execute the command in.</param>
 /// <returns>The number of jobs that match the given filter.</returns>
 public abstract int GetJobCount(string likeName, JobStatus? withStatus, string inSchedule, IJobStoreTransaction transaction);
예제 #12
0
 /// <summary>
 /// Gets a job by ID.
 /// </summary>
 /// <param name="id">The ID of the job to get.</param>
 /// <param name="transaction">The transaction to execute the command in.</param>
 /// <returns>The job with the given ID.</returns>
 public abstract JobRecord GetJob(int id, IJobStoreTransaction transaction);
예제 #13
0
 /// <summary>
 /// Deletes all jobs older than the given date.
 /// </summary>
 /// <param name="olderThan">The date to delete jobs older than.</param>
 /// <param name="transaction">The transaction to execute the command in.</param>
 public abstract void DeleteJobs(DateTime olderThan, IJobStoreTransaction transaction);
예제 #14
0
        /// <summary>
        /// Re-enqueues a job for a retry if more retries are available.
        /// </summary>
        /// <param name="job">The job to re-enqueue.</param>
        /// <param name="trans">The transaction to use when saving the new job record, if applicable.</param>
        private void EnqueueJobForRetry(IJob job, IJobStoreTransaction trans)
        {
            if (job != null && job.TryNumber <= job.Retries)
            {
                JobRecord record = job.CreateRecord();
                record.TryNumber = job.TryNumber + 1;
                record.QueueDate = DateTime.UtcNow.AddMilliseconds(this.RetryTimeout);
                this.store.SaveJob(record, trans);

                this.RaiseEvent(this.RetryEnqueued, new JobRecordEventArgs(record));
            }
        }
예제 #15
0
 /// <summary>
 /// Saves the given job record, either creating it or updating it.
 /// </summary>
 /// <param name="record">The job to save.</param>
 /// <param name="transaction">The transaction to execute the command in.</param>
 public abstract void SaveJob(JobRecord record, IJobStoreTransaction transaction);
예제 #16
0
        /// <summary>
        /// Performs the concrete finishing of the given job run.
        /// </summary>
        /// <param name="run">A job run to finish.</param>
        /// <param name="record">The run's related record.</param>
        /// <param name="trans">The transaction to access the job store in.</param>
        private void FinishJobRun(JobRun run, JobRecord record, IJobStoreTransaction trans)
        {
            record.FinishDate = run.FinishDate;

            if (run.ExecutionException != null)
            {
                record.Exception = new ExceptionXElement(run.ExecutionException).ToString();
                record.Status = JobStatus.Failed;

                this.RaiseEvent(this.Error, new JobErrorEventArgs(record, run.ExecutionException));
                this.EnqueueJobForRetry(run.Job, trans);
            }
            else if (run.WasRecovered)
            {
                record.Status = JobStatus.Interrupted;
            }
            else
            {
                record.Status = JobStatus.Succeeded;
            }

            if (this.DeleteRecordsOnSuccess)
            {
                this.store.DeleteJob(record.Id.Value, trans);
            }
            else
            {
                this.store.SaveJob(record, trans);
            }

            this.runs.Remove(record.Id.Value);
            this.RaiseEvent(this.FinishJob, new JobRecordEventArgs(record));
        }
예제 #17
0
 /// <summary>
 /// Deletes all jobs in the job store.
 /// </summary>
 /// <param name="transaction">The transaction to execute the command in.</param>
 public abstract void DeleteAllJobs(IJobStoreTransaction transaction);