Пример #1
0
 internal WorkerRunner(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
 {
     WorkerCard             = workerCard;
     WorkAssignment         = workAssignment;
     CommittableTransaction = committableTransaction;
     Command        = Command.Run;
     quitGracefully = false;
 }
Пример #2
0
 internal WorkerRunner(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
 {
     WorkerCard = workerCard;
     WorkAssignment = workAssignment;
     CommittableTransaction = committableTransaction;
     Command = Command.Run;
     quitGracefully = false;
 }
 public WorkerStatistics(WorkAssignment workAssignment, string machineName, Pipe reportPipe)
 {
     WorkerBadge = workAssignment.WorkerBadge;
     WorkerBorn = DateTime.Now;
     HeartBeatInterval = new TimeSpan(0, 0, 1);
     PreviousHeartBeatSentTime = WorkerBorn;
     CurrentHeartBeatSentTime = WorkerBorn;
     if (reportPipe == null) throw new ArgumentException("reportPipe is null");
     ReportPipe = reportPipe;
 }
Пример #4
0
        public WorkerBadge(WorkAssignment workAssignment)
        {
            SectionName = workAssignment.WorkRequest.SectionName;
            RoleSlotToken = workAssignment.RoleSlotToken;

            MachineName = Environment.MachineName;

            WorkerId = workAssignment.WorkRequest.PipelineId + "_" +
                       workAssignment.WorkRequest.SectionName + "_" +
                       workAssignment.RoleSlotToken.SlotId + "_" +
                       Environment.MachineName;
        }
Пример #5
0
        public WorkerBadge(WorkAssignment workAssignment)
        {
            SectionName   = workAssignment.WorkRequest.SectionName;
            RoleSlotToken = workAssignment.RoleSlotToken;

            MachineName = Environment.MachineName;

            WorkerId = workAssignment.WorkRequest.PipelineId + "_" +
                       workAssignment.WorkRequest.SectionName + "_" +
                       workAssignment.RoleSlotToken.SlotId + "_" +
                       Environment.MachineName;
        }
 public WorkerStatistics(WorkAssignment workAssignment, string machineName, Pipe reportPipe)
 {
     WorkerBadge               = workAssignment.WorkerBadge;
     WorkerBorn                = DateTime.Now;
     HeartBeatInterval         = new TimeSpan(0, 0, 1);
     PreviousHeartBeatSentTime = WorkerBorn;
     CurrentHeartBeatSentTime  = WorkerBorn;
     if (reportPipe == null)
     {
         throw new ArgumentException("reportPipe is null");
     }
     ReportPipe = reportPipe;
 }
Пример #7
0
        private void EmployWorkersForJob(RunningJob runningJob)
        {
            foreach (JobSection jobSection in runningJob.Sections)
            {
                if (null == jobSection.WorkerCard)
                {
                    continue;                                // We don't have workers for this role
                }
                uint availableWorkers = jobSection.WorkerCard.MaxNumOfInstances - GetWorkingWorkersNumber(jobSection.RoleType);
                if (availableWorkers == 0)
                {
                    continue;                        // All available workers for that role are busy
                }
                // Try to hire ONE worker for the role.
                // We should not hire more than one worker for the role in one iteration to give other WorkerManagers a chance to take some workload.
                RoleSlotToken roleSlotToken = null;

                var         transaction = new CommittableTransaction(TransactionManager.MaximumTimeout);
                Transaction oldAmbient  = Transaction.Current;
                Transaction.Current = transaction;
                try
                {
                    roleSlotToken = jobSection.GetFreeSlot();
                }
                finally
                {
                    Transaction.Current = oldAmbient;
                    if (null == roleSlotToken)
                    {
                        transaction.Rollback();
                        transaction.Dispose();
                    }
                }

                if (null == roleSlotToken)
                {
                    continue;
                }
                WorkAssignment workAssignment = new WorkAssignment(jobSection.WorkRequest, roleSlotToken,
                                                                   runningJob.JobId, runningJob.ScheduleRunDuration, runningJob.ScheduleCreatedBy, runningJob.NotificationId, runningJob.Frequency);
                EmployWorker(jobSection.WorkerCard, workAssignment, transaction);
                jobSection.WorkerIDs.Add(workAssignment.WorkerId);
            }
        }
Пример #8
0
        internal void EmployWorker(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
        {
            WorkerRunner workerRunner = null;

            switch (workAssignment.WorkRequest.WorkerIsolationLevel)
            {
            case WorkerIsolationLevel.SeparateAppDomain:
                workerRunner = new WorkerRunnerAppDomain(workerCard, workAssignment, committableTransaction);
                break;

            case WorkerIsolationLevel.SeparateProcess:
                workerRunner = new WorkerRunnerProcess(workerCard, workAssignment, committableTransaction);

                // Debug
                //workerRunner = new WorkerRunnerThread(workerCard, WorkAssignment, committableTransaction);
                break;

            case WorkerIsolationLevel.SeparateThread:
            case WorkerIsolationLevel.Default:
            default:
                workerRunner = new WorkerRunnerThread(workerCard, workAssignment, committableTransaction);
                break;
            }

            try
            {
                AllWorkerRunners.Add(workAssignment.WorkerId, workerRunner);
            }
            catch (Exception ex)
            {
                Tracer.Error("AllWorkerRunners.Add({0}) caused exception: {1}", workAssignment.WorkerId, ex);
                foreach (string workerId in AllWorkerRunners.Keys)
                {
                    Tracer.Error("AllWorkerRunners contains worker {0}", workerId);
                }
                throw;
            }
            workerRunner.Run();
        }
Пример #9
0
        private void EmployWorkersForJob(RunningJob runningJob)
        {
            foreach (JobSection jobSection in runningJob.Sections)
            {
                if (null == jobSection.WorkerCard) continue; // We don't have workers for this role
                uint availableWorkers = jobSection.WorkerCard.MaxNumOfInstances - GetWorkingWorkersNumber(jobSection.RoleType);
                if (availableWorkers == 0) continue; // All available workers for that role are busy

                // Try to hire ONE worker for the role.
                // We should not hire more than one worker for the role in one iteration to give other WorkerManagers a chance to take some workload.
                RoleSlotToken roleSlotToken = null;

                var transaction = new CommittableTransaction(TransactionManager.MaximumTimeout);
                Transaction oldAmbient = Transaction.Current;
                Transaction.Current = transaction;
                try
                {
                    roleSlotToken = jobSection.GetFreeSlot();
                }
                finally
                {
                    Transaction.Current = oldAmbient;
                    if (null == roleSlotToken)
                    {
                        transaction.Rollback();
                        transaction.Dispose();
                    }
                }

                if (null == roleSlotToken)
                {
                    continue;
                }
                WorkAssignment workAssignment = new WorkAssignment(jobSection.WorkRequest, roleSlotToken,
                    runningJob.JobId, runningJob.ScheduleRunDuration, runningJob.ScheduleCreatedBy, runningJob.NotificationId, runningJob.Frequency);
                EmployWorker(jobSection.WorkerCard, workAssignment, transaction);
                jobSection.WorkerIDs.Add(workAssignment.WorkerId);
            }
        }
Пример #10
0
 public WorkerStateChangedMessage(WorkAssignment workAssignment, WorkerState workerState)
 {
     WorkerBadge = workAssignment.WorkerBadge;
     WorkerState = workerState;
 }
Пример #11
0
 public WorkerStateChangedMessage(WorkAssignment workAssignment, WorkerState workerState)
 {
     WorkerBadge = workAssignment.WorkerBadge;
     WorkerState = workerState;
 }
Пример #12
0
 internal WorkerRunnerThread(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
     : base(workerCard, workAssignment, committableTransaction)
 {
 }
Пример #13
0
        internal void EmployWorker(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
        {
            WorkerRunner workerRunner = null;

            switch (workAssignment.WorkRequest.WorkerIsolationLevel)
            {
                case WorkerIsolationLevel.SeparateAppDomain:
                    workerRunner = new WorkerRunnerAppDomain(workerCard, workAssignment, committableTransaction);
                    break;
                case WorkerIsolationLevel.SeparateProcess:
                    workerRunner = new WorkerRunnerProcess(workerCard, workAssignment, committableTransaction);

                    // Debug
                    //workerRunner = new WorkerRunnerThread(workerCard, WorkAssignment, committableTransaction);
                    break;
                case WorkerIsolationLevel.SeparateThread:
                case WorkerIsolationLevel.Default:
                default:
                    workerRunner = new WorkerRunnerThread(workerCard, workAssignment, committableTransaction);
                    break;
            }

            try
            {
                AllWorkerRunners.Add(workAssignment.WorkerId, workerRunner);
            }
            catch (Exception ex)
            {
                Tracer.Error("AllWorkerRunners.Add({0}) caused exception: {1}", workAssignment.WorkerId, ex);
                foreach (string workerId in AllWorkerRunners.Keys)
                {
                    Tracer.Error("AllWorkerRunners contains worker {0}", workerId);                    
                }
                throw;
            }
            workerRunner.Run();
        }
Пример #14
0
 internal WorkerRunnerThread(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction)
     : base(workerCard, workAssignment, committableTransaction)
 {
 }