Производственный сервер, использующий PM2, иногда не выполнял действия внутри routeChangeSuccess - PullRequest
0 голосов
/ 26 сентября 2018

В настоящее время я использую Angular 1.3.8 и ExpressJS 4.9.8 и обнаружил, что на Производственном сервере иногда не выполнялось действие, которое я определил в контроллере маршрута AngularJS routeChangeSuccess.Я запустил свое приложение NodeJS, используя PM2, режим кластера.Итак, сейчас у меня есть процесс 1-4.Весь процесс выполняется с NODE_ENV = production.

Например, вот один из кодов, которые будут выполняться при загрузке страницы:

app.controller('ViewController', ['$scope', '$http', '$route', '$location', '$sce', '$window', '$q', '$modal', '$interval', '$upload', 'ActivityService', function($scope, $http, $route, $location, $sce, $window, $q, $modal, $interval, $upload, ActivityService) {

    $scope.activity = {};
    $scope.organization = {};
    $scope.user = {};
    $scope.questions = [];

    $scope.application = {
        app: []
    };

    $scope.stars = [];

    $scope.spinnerloading = false;

    $scope.isRequireCv = false;
    $scope.isCVUploaded = false;

    /* Main Functions */

    $scope.$on('$routeChangeSuccess', function(event, routeData) {
        // Pop Up on Activities Search Page
        $scope.popupDontGo();

        _.each(ActivityService.getActivityTypes(), function(type) {
            $scope.TYPES[type.value] = type.name;
        });

        /*Use promise for multiple call API*/
        $q.all([$http.get('/api/activity/' + $route.current.params.activity_id)
                .then(function(data) {
                    /*Activity*/
                    indorelawan.verbose && console.log(data.data);

                    $scope.organization = data.data.result.organization;
                    $scope.activity = data.data.result;
                    $scope.description = $sce.trustAsHtml(data.data.result.description);
                    $scope.isRequireCv = data.data.result.isRequireCv;

                    var ratings = $scope.calculateRating();
                    var share_current_url = window.location.pathname;

                    for (var i = 0; i < ratings; i++) {
                        $scope.stars.push("fa fa-star fg-yellow");
                    }
                    for (var i = 0; i < 5 - ratings; i++) {
                        $scope.stars.push("fa fa-star");
                    }

                    return data;
                }),
                $http.get('/api/user/current')
                .then(function(data) {
                    /*User*/
                    $scope.user = data.data.result;

                    if (typeof $scope.user.cv == 'undefined' || $scope.user.cv == null) {
                        $scope.isCVUploaded = false;
                    } else {
                        $scope.isCVUploaded = true;
                    }

                    return data;
                })
        ]).then(function(data) {
            /*Check user*/
            if (data[1].data.result.role == 'manager') {
                if (url['ref'] != null && $scope.user.organization._id == $scope.activity.organization._id) $('#notificationPopup').modal('show');
            } else if (data[1].data.result.role == 'user') {
                var found = _.find(data[1].data.result.volunteers, function(volunteer) {
                    return volunteer.activity == $scope.activity._id
                });
                if (url['ref'] == 'daftar' && found==undefined) $('#previewModal').modal('show');
            }
        });

        $http
        .get('/api/activity/' + $route.current.params.activity_id + '/volunteer-in-process')
        .success(function(data) {
            $scope.volunteers = data.results;
            $scope.count = data.count;
            $scope.hasNext = data.has_next;
            $scope.next = data.next;
        });

        // TODO: Convert using service.
        $http
        .get('/api/user/current/volunteer')
        .success(function(data) {
            $scope.user.volunteers = data.results;
        });

        //Call All Questions
        $http
        .get('/api/activity/' + $route.current.params.activity_id +'/questions')
        .success(function(data) {
            $scope.questions = data.results;
        });

    });
    ...
}]);

На основе кода при загрузке страниц существует 5 API, которые собираютсябыть вызванным, то есть:

  • / api / activity / activity_id /
  • / api / user / current /
  • / api / Activity / Activity_id / волонтер-в процессе
  • / api / пользователь / текущий / волонтер
  • / api / activity / activity_id / questions

Теперь при запуске этого на локальном хостеработает отлично.Но на рабочем сервере иногда страница не загружала API.Вот пример сравнения журналов:

Normal:
GET /activity/activity_id 200 --
GET /api/activity/activity_id/ 200 --
GET /api/user/current/ 200 --
GET /api/activity/activity_id/volunteer-in-process 200 --
GET /api/user/current/volunteer 200 --
GET /api/activity/activity_id/questions 200 --
GET / 200 --
GET /activity/search 200 --

Error:
GET /activity/activity_id 200 --
GET / 200 --
GET /activity/search 200 --

Как будто они пропустили часть routeChangeSuccess, что привело нас к бесконечной загрузке в Angular, из-за которой ng-cloak никогда не исчезает.Что я могу сделать, чтобы предотвратить это?Потому что это делает сайт выглядит очень медленно.

...