private void ScanForPackages()
        {
            lock (this)
            {
                log.Info("Scanning directory {0} for packages", _baseDir);
                Dictionary<string, PackageInfo> names = new Dictionary<string, PackageInfo>();

                if (Directory.Exists(_baseDir))
                {
                    string[] pkgs = Directory.GetFiles(_baseDir, "*.ngpk", SearchOption.AllDirectories);
                    foreach (string pkg in pkgs)
                    {
                        log.Info("Found package file {0}", pkg);
                        try
                        {
                            ProcessPackageStore ps = new ProcessPackageStore(pkg);
                            PackageDefinition pd = ps.GetPackageDefinition();
                            log.Info("Successfully loaded package {0} from {1}", pd.PackageName, pkg);
                            PackageInfo pi = new PackageInfo();
                            pi.PackageStore = ps;
                            pi.PackageStore.ProcessReload += new ProcessPackageStore.ProcessReloadingDelegate(PackageStore_ProcessReload);
                            names[pd.PackageName] = pi;
                        }
                        catch (Exception ex)
                        {
                            log.Error("Error reading package file: {0}: {1}", pkg, ex);
                            DiagnosticEvent de = new DiagnosticEvent("PackageRepository", ex);
                            de.Message = string.Format("Error loading package {0}", pkg);
                            if (MessageBus != null) MessageBus.Notify("ProcessPackageRepository", "Error", de, false);
                        }
                    }
                }
                _packageCache = names;
            }
        }
예제 #2
0
        protected void ManagerProc()
        {
            STPStartInfo startInfo = new STPStartInfo();
            startInfo.MaxWorkerThreads = ExecutionThreads;
            SmartThreadPool st = new SmartThreadPool(startInfo);

            try
            {
                st.Start();
                while (!_stop)
                {
                    try
                    {
                        if (!st.IsIdle)
                        {
                            log.Warn("Thread pool not idle, waiting...");
                        }
                        else
                        {
                            log.Debug("Querying for ready processes");
                            IList<string> procs = Environment.GetKickableProcesses();

                            foreach (string procId in procs)
                            {
                                log.Debug("Queue <- {0}", procId);
                                st.QueueWorkItem(new WorkItemCallback(this.KickProcess), procId);
                            }
                            log.Debug("Enqueued {0} processes", procs.Count);
                        }
                        if (st.IsIdle)
                        {
                            _procNotifier.WaitOne(TimeSpan.FromSeconds(15.0), true);
                        }
                        else
                        {
                            //TODO: problem here - if some process takes a long time to
                            //kick, it will block process scheduling
                            //solution: we shouldn't wait for idle thread pool, but
                            //pump the queue all the time.
                            st.WaitForIdle(TimeSpan.FromHours(1.0));
                        }
                    }
                    catch (ThreadAbortException ex) {}
                    catch (ThreadInterruptedException ex) {}
                    catch (Exception ex)
                    {
                        log.Error("Manager thread error: {0}", ex);
                        DiagnosticEvent de = new DiagnosticEvent("NGEngine", ex);
                        de.Message = "NGEngine scheduler thread error";
                        MessageBus.Notify("NGengine", "Error", de, false);
                        if(!_stop) Thread.Sleep(30000);
                    }
                }
            }
            catch (ThreadAbortException ex) {}
            catch (ThreadInterruptedException ex) {}
            catch (Exception ex)
            {
                log.Error("Manager thread error: {0}", ex);
            }
            finally
            {
                log.Info("Shutting down thread pool");
                st.Shutdown(true, 10000);
                log.Info("Thread pool shut down");
                st.Dispose();
            }
        }