<commit_before>package bootstrapper

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"strconv"
	"time"

	"github.com/cloudfoundry-incubator/cf-mysql-bootstrap/clock"
	"github.com/cloudfoundry-incubator/cf-mysql-bootstrap/config"
	"github.com/pivotal-golang/lager"
)

type Bootstrapper struct {
	rootConfig *config.Config
	clock      clock.Clock
}

func New(rootConfig *config.Config, clock clock.Clock) *Bootstrapper {
	return &Bootstrapper{
		rootConfig: rootConfig,
		clock:      clock,
	}
}

func (b *Bootstrapper) Run() error {
	logger := b.rootConfig.Logger

	for _, url := range b.rootConfig.HealthcheckURLs {
		stopMysqlUrl := fmt.Sprintf("%s/%s", url, b.rootConfig.ShutDownMysql)
		resp, err := http.Get(stopMysqlUrl)
		if err != nil {
			return fmt.Errorf("Failed to stop mysql: %s", err.Error())
		}

		if resp.StatusCode != http.StatusOK {
			responseBody := ""
			if resp.Body != nil {
				responseBytes, _ := ioutil.ReadAll(resp.Body)
				responseBody = string(responseBytes)
			}
			return fmt.Errorf("Non 200 response from stopping mysql at %s: %s", stopMysqlUrl, responseBody)
		}

		logger.Info(fmt.Sprintf("Successfully sent stop request to URL: %s", stopMysqlUrl))
	}

	pollingIntervalInSec := 3
	timeoutInSec := 30
	maxIterations := timeoutInSec / pollingIntervalInSec
	for _, url := range b.rootConfig.HealthcheckURLs {
		statusUrl := fmt.Sprintf("%s/%s", url, b.rootConfig.MysqlStatus)
		stoppedSuccessfully := false

		for i := 0; i < maxIterations; i++ {
			resp, err := http.Get(statusUrl)
			if err != nil {
				return fmt.Errorf("Failed to get mysql status: %s", err.Error())
			}

			responseBody := ""
			if resp.Body != nil {
				responseBytes, _ := ioutil.ReadAll(resp.Body)
				responseBody = string(responseBytes)
			}
<commit_msg>Changed polling interval, and timeout<commit_after>package bootstrapper

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"strconv"
	"time"

	"github.com/cloudfoundry-incubator/cf-mysql-bootstrap/clock"
	"github.com/cloudfoundry-incubator/cf-mysql-bootstrap/config"
	"github.com/pivotal-golang/lager"
)

type Bootstrapper struct {
	rootConfig *config.Config
	clock      clock.Clock
}

func New(rootConfig *config.Config, clock clock.Clock) *Bootstrapper {
	return &Bootstrapper{
		rootConfig: rootConfig,
		clock:      clock,
	}
}

func (b *Bootstrapper) Run() error {
	logger := b.rootConfig.Logger

	for _, url := range b.rootConfig.HealthcheckURLs {
		stopMysqlUrl := fmt.Sprintf("%s/%s", url, b.rootConfig.ShutDownMysql)
		resp, err := http.Get(stopMysqlUrl)
		if err != nil {
			return fmt.Errorf("Failed to stop mysql: %s", err.Error())
		}

		if resp.StatusCode != http.StatusOK {
			responseBody := ""
			if resp.Body != nil {
				responseBytes, _ := ioutil.ReadAll(resp.Body)
				responseBody = string(responseBytes)
			}
			return fmt.Errorf("Non 200 response from stopping mysql at %s: %s", stopMysqlUrl, responseBody)
		}

		logger.Info(fmt.Sprintf("Successfully sent stop request to URL: %s", stopMysqlUrl))
	}

	pollingIntervalInSec := 5
	timeoutInSec := 60
	maxIterations := timeoutInSec / pollingIntervalInSec
	for _, url := range b.rootConfig.HealthcheckURLs {
		statusUrl := fmt.Sprintf("%s/%s", url, b.rootConfig.MysqlStatus)
		stoppedSuccessfully := false

		for i := 0; i < maxIterations; i++ {
			resp, err := http.Get(statusUrl)
			if err != nil {
				return fmt.Errorf("Failed to get mysql status: %s", err.Error())
			}

			responseBody := ""
			if resp.Body != nil {
				responseBytes, _ := ioutil.ReadAll(resp.Body)
				responseBody = string(responseBytes)
			}

{'fraction_non_alphanumeric': 0.134180790960452, 'fraction_numerical': 0.0039548022598870055, 'mean_word_length': 3.884137931034483, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1655830', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1223, 'n_words': 272}