Пример #1
0
        public void Decrement(DateTime?now = null)
        {
            // This works in three steps:
            //
            // - First, the planned quantity of the schedules are reduced to equal the total number of parts being machined, completed,
            //   or about to be loaded.
            // - Next, the quantites that were removed are recorded.
            // - Finally, the Queues code in Queues.cs will update the material available and remove any allocated castings on
            //   the schedule.
            //
            // We are protected against crashes and failures:
            // - If the a failure happens before the decrement quantities are recorded, the next decrement will
            //   resume and continue reducing the mazak planned quantities.  The decrement quantities are then
            //   calculated by comparing the original job plan quantity with the current mazak schedule quantity, no matter
            //   when the mazak schedule was reduced.
            //
            // - If a failure happens after the decrement quantities are recorded, the job will not be decremented again because
            //   the code checks if a previous decrement has happended.  The queues code will keep re-trying to sync the material
            //   quantities with the new scheduled quantities.

            var jobs = JobsToDecrement(_read.LoadSchedulesAndLoadActions());

            Log.Debug("Found jobs to decrement {@jobs}", jobs);

            if (jobs.Count == 0)
            {
                return;
            }

            ReducePlannedQuantity(jobs);
            RecordDecrement(jobs, now);
        }
Пример #2
0
        public void SinglePathSingleProc()
        {
            // plan 50, completed 30, 5 in proc and 15 not yet started
            _read.LoadSchedulesAndLoadActions().Returns(new MazakSchedulesAndLoadActions()
            {
                Schedules = new[] {
                    new MazakScheduleRow()
                    {
                        Id               = 15,
                        Comment          = MazakPart.CreateComment("uuuu", new[] { 1 }, false),
                        PartName         = "pppp:1",
                        PlanQuantity     = 50,
                        CompleteQuantity = 30,
                        Processes        = new List <MazakScheduleProcessRow> {
                            new MazakScheduleProcessRow()
                            {
                                MazakScheduleRowId      = 15,
                                FixQuantity             = 1,
                                ProcessNumber           = 1,
                                ProcessMaterialQuantity = 15,
                                ProcessExecuteQuantity  = 5
                            }
                        }
                    }
                }
            });

            var j = new JobPlan("uuuu", 1);

            j.PartName = "pppp";
            j.SetPlannedCyclesOnFirstProcess(path: 1, numCycles: 50);
            _jobDB.AddJobs(new NewJobs()
            {
                Jobs = new List <JobPlan> {
                    j
                }
            }, null);

            var now = DateTime.UtcNow;

            _decr.Decrement(now);

            _write.Schedules.Count.Should().Be(1);
            var sch = _write.Schedules[0];

            sch.Id.Should().Be(15);
            sch.PlanQuantity.Should().Be(35);
            sch.Processes.Should().BeEmpty();

            _jobDB.LoadDecrementsForJob("uuuu").Should().BeEquivalentTo(new[] {
                new InProcessJobDecrement()
                {
                    DecrementId = 0,
                    TimeUTC     = now,
                    Quantity    = 50 - 35
                }
            });
        }
Пример #3
0
        public void ThreadFunc()
        {
            for (; ;)
            {
                try
                {
                    var sleepTime = TimeSpan.FromMinutes(1);
                    Log.Debug("Sleeping for {mins} minutes", sleepTime.TotalMinutes);
                    var ret = WaitHandle.WaitAny(new WaitHandle[] { _shutdown, _newLogFile, _recheckQueues }, sleepTime, false);
                    if (ret == 0)
                    {
                        Log.Debug("Thread shutdown");
                        return;
                    }

                    Thread.Sleep(TimeSpan.FromSeconds(1));

                    var mazakData = _readDB.LoadSchedulesAndLoadActions();
                    var logs      = LoadLog(_log.MaxForeignID());
                    var trans     = new LogTranslation(_jobDB, _log, mazakData, _settings,
                                                       le => MazakLogEvent?.Invoke(le)
                                                       );
                    var sendToExternal = new List <BlackMaple.MachineFramework.MaterialToSendToExternalQueue>();
                    foreach (var ev in logs)
                    {
                        try
                        {
                            sendToExternal.AddRange(trans.HandleEvent(ev));
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex, "Error translating log event at time " + ev.TimeUTC.ToLocalTime().ToString());
                        }
                    }

                    DeleteLog(_log.MaxForeignID());

                    _queues.CheckQueues(mazakData);

                    if (sendToExternal.Count > 0)
                    {
                        _sendToExternal.Post(sendToExternal).Wait(TimeSpan.FromSeconds(30));
                    }

                    if (logs.Count > 0)
                    {
                        NewEntries?.Invoke();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error during log data processing");
                }
            }
        }
Пример #4
0
        private void HandleElapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            lock (_lock)
            {
                try
                {
                    var mazakData = _readDB.LoadSchedulesAndLoadActions();
                    var logs      = LoadLog(_log.MaxForeignID());
                    var trans     = new LogTranslation(_jobDB, _log, mazakData, FMSSettings,
                                                       le => MazakLogEvent?.Invoke(le)
                                                       );
                    var sendToExternal = new List <BlackMaple.MachineFramework.MaterialToSendToExternalQueue>();
                    foreach (var ev in logs)
                    {
                        try
                        {
                            sendToExternal.AddRange(trans.HandleEvent(ev));
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex, "Error translating log event at time " + ev.TimeUTC.ToLocalTime().ToString());
                        }
                    }

                    _queues.CheckQueues(mazakData);

                    if (sendToExternal.Count > 0)
                    {
                        _sendToExternal.Post(sendToExternal);
                    }

                    if (logs.Count > 0)
                    {
                        NewEntries?.Invoke();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Unhandled error processing log");
                }
            }
        }