BlueCollar.Worker.PruneOrphans C# (CSharp) Method

PruneOrphans() private method

Prunes orphaned jobs assigned to this worker that for one reason or another didn't get marked as interrupted.
private PruneOrphans ( ) : void
return void
        internal void PruneOrphans()
        {
            long? currentId = null;

            lock (this.runLocker)
            {
                currentId = this.currentRecord != null ? this.currentRecord.Id : null;
            }

            using (IRepository repository = this.repositoryFactory.Create())
            {
                using (IDbTransaction transaction = repository.BeginTransaction())
                {
                    foreach (WorkingRecord working in repository.GetWorkingForWorker(this.Id, currentId, transaction))
                    {
                        if (working.Id != currentId)
                        {
                            HistoryRecord history = CreateHistory(working, HistoryStatus.Interrupted);
                            repository.DeleteWorking(working.Id.Value, transaction);
                            repository.CreateHistory(history, transaction);
                        }
                    }

                    transaction.Commit();
                }
            }
        }