protected function calculatePollTimeout()
    {
        if ($this->getScheduler()->isEmpty()) {
            return 60000;
        }

        $nextSchedule = $this->getScheduler()->top();
        $nextTime = $nextSchedule->getNextRunDate();

        $timeout = $nextTime-time();
        if ($timeout > 60) {
            $timeout = 60;
        }
        
        if ($timeout < 0) {
            return 0;
        }

        return $timeout*1000;
    }