本文整理汇总了Golang中github.com/buildkite/agent/logger.Debug函数的典型用法代码示例。如果您正苦于以下问题:Golang Debug函数的具体用法?Golang Debug怎么用?Golang Debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Stop
// Stops the agent from accepting new work and cancels any current work it's
// running
func (a *AgentWorker) Stop() {
// Only allow one stop to run at a time (because we're playing with channels)
a.stopMutex.Lock()
if a.stopping {
logger.Debug("Agent is already stopping...")
return
} else {
logger.Debug("Stopping the agent...")
}
// If ther'es a running job, kill it.
if a.jobRunner != nil {
a.jobRunner.Kill()
}
// If we have a ticker, stop it, and send a signal to the stop channel,
// which will cause the agent worker to stop looping immediatly.
if a.ticker != nil {
close(a.stop)
}
// Mark the agent as stopping
a.stopping = true
// Unlock the stop mutex
a.stopMutex.Unlock()
}
示例2: Worker
// The actual log streamer worker
func Worker(id int, ls *LogStreamer) {
logger.Debug("[LogStreamer/Worker#%d] Worker is starting...", id)
var chunk *LogStreamerChunk
for {
// Get the next chunk (pointer) from the queue. This will block
// until something is returned.
chunk = <-ls.queue
// If the next chunk is nil, then there is no more work to do
if chunk == nil {
break
}
// Upload the chunk
err := ls.Callback(chunk)
if err != nil {
atomic.AddInt32(&ls.ChunksFailedCount, 1)
logger.Error("Giving up on uploading chunk %d, this will result in only a partial build log on Buildkite", chunk.Order)
}
// Signal to the chunkWaitGroup that this one is done
ls.chunkWaitGroup.Done()
}
logger.Debug("[LogStreamer/Worker#%d] Worker has shutdown", id)
}
示例3: Upload
func (u *S3Uploader) Upload(artifact *api.Artifact) error {
permission := "public-read"
if os.Getenv("BUILDKITE_S3_ACL") != "" {
permission = os.Getenv("BUILDKITE_S3_ACL")
} else if os.Getenv("AWS_S3_ACL") != "" {
permission = os.Getenv("AWS_S3_ACL")
}
// The dirtiest validation method ever...
if permission != "private" &&
permission != "public-read" &&
permission != "public-read-write" &&
permission != "authenticated-read" &&
permission != "bucket-owner-read" &&
permission != "bucket-owner-full-control" {
logger.Fatal("Invalid S3 ACL `%s`", permission)
}
Perms := s3.ACL(permission)
logger.Debug("Reading file \"%s\"", artifact.AbsolutePath)
data, err := ioutil.ReadFile(artifact.AbsolutePath)
if err != nil {
return errors.New("Failed to read file " + artifact.AbsolutePath + " (" + err.Error() + ")")
}
logger.Debug("Uploading \"%s\" to bucket with permission `%s`", u.artifactPath(artifact), permission)
err = u.Bucket.Put(u.artifactPath(artifact), data, u.mimeType(artifact), Perms, s3.Options{})
if err != nil {
return errors.New(fmt.Sprintf("Failed to PUT file \"%s\" (%s)", u.artifactPath(artifact), err.Error()))
}
return nil
}
示例4: Start
func (h *HeaderTimesStreamer) Start() error {
h.streaming = true
go func() {
logger.Debug("[HeaderTimesStreamer] Streamer has started...")
for true {
// Break out of streaming if it's finished. We also
// need to aquire a read lock on the flag because it
// can be modified by other routines.
h.streamingMutex.Lock()
if !h.streaming {
break
}
h.streamingMutex.Unlock()
// Upload any pending header times
h.Upload()
// Sleep for a second and try upload some more later
time.Sleep(1 * time.Second)
}
logger.Debug("[HeaderTimesStreamer] Streamer has finished...")
}()
return nil
}
示例5: Upload
func (h *HeaderTimesStreamer) Upload() {
// Store the current cursor value
c := h.cursor
// Grab only the times that we haven't uploaded yet. We need to aquire
// a lock since other routines may be adding to it.
h.timesMutex.Lock()
length := len(h.times)
times := h.times[h.cursor:length]
h.timesMutex.Unlock()
// Construct the payload to send to the server
payload := map[string]string{}
for index, time := range times {
payload[strconv.Itoa(h.cursor+index)] = time
}
// Save the cursor we're up to
h.cursor = length
// How many times are we uploading this time
timesToUpload := len(times)
// Do we even have some times to upload
if timesToUpload > 0 {
// Call our callback with the times for upload
logger.Debug("[HeaderTimesStreamer] Uploading header times %d..%d", c, length-1)
h.UploadCallback(c, length, payload)
logger.Debug("[HeaderTimesStreamer] Finished uploading header times %d..%d", c, length-1)
// Decrement the wait group for every time we've uploaded.
h.uploadWaitGroup.Add(timesToUpload * -1)
}
}
示例6: Do
// Do sends an API request and returns the API response. The API response is
// JSON decoded and stored in the value pointed to by v, or returned as an
// error if an API error has occurred. If v implements the io.Writer
// interface, the raw response body will be written to v, without attempting to
// first decode it.
func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
var err error
if c.DebugHTTP {
// If the request is a multi-part form, then it's probably a
// file upload, in which case we don't want to spewing out the
// file contents into the debug log (especially if it's been
// gzipped)
var requestDump []byte
if strings.Contains(req.Header.Get("Content-Type"), "multipart/form-data") {
requestDump, err = httputil.DumpRequestOut(req, false)
} else {
requestDump, err = httputil.DumpRequestOut(req, true)
}
logger.Debug("ERR: %s\n%s", err, string(requestDump))
}
ts := time.Now()
logger.Debug("%s %s", req.Method, req.URL)
resp, err := c.client.Do(req)
if err != nil {
return nil, err
}
logger.Debug("↳ %s %s (%s %s)", req.Method, req.URL, resp.Status, time.Now().Sub(ts))
defer resp.Body.Close()
defer io.Copy(ioutil.Discard, resp.Body)
response := newResponse(resp)
if c.DebugHTTP {
responseDump, err := httputil.DumpResponse(resp, true)
logger.Debug("\nERR: %s\n%s", err, string(responseDump))
}
err = checkResponse(resp)
if err != nil {
// even though there was an error, we still return the response
// in case the caller wants to inspect it further
return response, err
}
if v != nil {
if w, ok := v.(io.Writer); ok {
io.Copy(w, resp.Body)
} else {
err = json.NewDecoder(resp.Body).Decode(v)
}
}
return response, err
}
示例7: Stop
func (h *HeaderTimesStreamer) Stop() {
logger.Debug("[HeaderTimesStreamer] Waiting for all the lines to be scanned")
h.scanWaitGroup.Wait()
logger.Debug("[HeaderTimesStreamer] Waiting for all the header times to be uploaded")
h.uploadWaitGroup.Wait()
// Since we're modifying the waitGroup and the streaming flag, we need
// to aquire a write lock.
h.streamingMutex.Lock()
h.streaming = false
h.streamingMutex.Unlock()
}
示例8: Stop
// Waits for all the chunks to be uploaded, then shuts down all the workers
func (ls *LogStreamer) Stop() error {
logger.Debug("[LogStreamer] Waiting for all the chunks to be uploaded")
ls.chunkWaitGroup.Wait()
logger.Debug("[LogStreamer] Shutting down all workers")
for n := 0; n < ls.Concurrency; n++ {
ls.queue <- nil
}
return nil
}
示例9: Run
// Runs the job
func (r *JobRunner) Run() error {
logger.Info("Starting job %s", r.Job.ID)
// Start the build in the Buildkite Agent API. This is the first thing
// we do so if it fails, we don't have to worry about cleaning things
// up like started log streamer workers, etc.
if err := r.startJob(time.Now()); err != nil {
return err
}
// Start the log streamer
if err := r.logStreamer.Start(); err != nil {
return err
}
// Start the process. This will block until it finishes.
if err := r.process.Start(); err != nil {
// Send the error as output
r.logStreamer.Process(fmt.Sprintf("%s", err))
} else {
// Add the final output to the streamer
r.logStreamer.Process(r.process.Output())
}
// Store the finished at time
finishedAt := time.Now()
// Wait until all the header times have finished uploading
logger.Debug("Waiting for header times to finish uploading")
r.headerTimesStreamer.Wait()
// Stop the log streamer. This will block until all the chunks have
// been uploaded
r.logStreamer.Stop()
// Warn about failed chunks
if r.logStreamer.ChunksFailedCount > 0 {
logger.Warn("%d chunks failed to upload for this job", r.logStreamer.ChunksFailedCount)
}
// Finish the build in the Buildkite Agent API
r.finishJob(finishedAt, r.process.ExitStatus, int(r.logStreamer.ChunksFailedCount))
// Wait for the routines that we spun up to finish
logger.Debug("Waiting for all other routines to finish")
r.wg.Wait()
logger.Info("Finished job %s", r.Job.ID)
return nil
}
示例10: onProcessStartCallback
func (r *JobRunner) onProcessStartCallback() {
// Start a routine that will grab the output every few seconds and send
// it back to Buildkite
go func() {
// Add to the wait group
r.wg.Add(1)
for r.process.Running {
// Send the output of the process to the log streamer
// for processing
r.logStreamer.Process(r.process.Output())
// Check the output in another second
time.Sleep(1 * time.Second)
}
// Mark this routine as done in the wait group
r.wg.Done()
logger.Debug("Routine that processes the log has finished")
}()
// Start a routine that will grab the output every few seconds and send it back to Buildkite
go func() {
// Add to the wait group
r.wg.Add(1)
for r.process.Running {
// Re-get the job and check it's status to see if it's been
// cancelled
jobState, _, err := r.APIClient.Jobs.GetState(r.Job.ID)
if err != nil {
// We don't really care if it fails, we'll just
// try again in a second anyway
logger.Warn("Problem with getting job state %s (%s)", r.Job.ID, err)
} else if jobState.State == "canceling" || jobState.State == "canceled" {
r.Kill()
}
// Check for cancellations every few seconds
time.Sleep(3 * time.Second)
}
// Mark this routine as done in the wait group
r.wg.Done()
logger.Debug("Routine that refreshes the job has finished")
}()
}
示例11: signal
func (p *Process) signal(sig os.Signal) error {
if p.command != nil && p.command.Process != nil {
logger.Debug("[Process] Sending signal: %s to PID: %d", sig.String(), p.Pid)
err := p.command.Process.Signal(syscall.SIGTERM)
if err != nil {
logger.Error("[Process] Failed to send signal: %s to PID: %d (%T: %v)", sig.String(), p.Pid, err, err)
return err
}
} else {
logger.Debug("[Process] No process to signal yet")
}
return nil
}
示例12: collect
func (a *ArtifactUploader) collect() (artifacts []*api.Artifact, err error) {
globPaths := strings.Split(a.Paths, ";")
for _, globPath := range globPaths {
workingDirectory := a.WorkingDirectory(globPath)
globPath = strings.TrimSpace(globPath)
if globPath != "" {
logger.Debug("Searching for %s", a.NormalizedPath(globPath))
files, err := glob.Glob(workingDirectory, globPath)
if err != nil {
return nil, err
}
for _, file := range files {
// Generate an absolute path for the artifact
absolutePath, err := filepath.Abs(file)
if err != nil {
return nil, err
}
fileInfo, err := os.Stat(absolutePath)
if fileInfo.IsDir() {
logger.Debug("Skipping directory %s", file)
continue
}
// Create a relative path (from the workingDirectory) to the artifact, by removing the
// first part of the absolutePath that is the workingDirectory.
relativePath := strings.Replace(absolutePath, workingDirectory, "", 1)
// Ensure the relativePath doesn't have a file seperator "/" as the first character
relativePath = strings.TrimPrefix(relativePath, string(os.PathSeparator))
// Build an artifact object using the paths we have.
artifact, err := a.build(relativePath, absolutePath, globPath)
if err != nil {
return nil, err
}
artifacts = append(artifacts, artifact)
}
}
}
return artifacts, nil
}
示例13: Setup
func (u *S3Uploader) Setup(destination string, debugHTTP bool) error {
u.Destination = destination
u.DebugHTTP = debugHTTP
// Try to auth with S3
auth, err := awsS3Auth()
if err != nil {
return errors.New(fmt.Sprintf("Error creating AWS S3 authentication: %s", err.Error()))
}
// Try and get the region
region, err := awsS3Region()
if err != nil {
return err
}
logger.Debug("Authorizing S3 credentials and finding bucket `%s` in region `%s`...", u.BucketName(), region.Name)
// Find the bucket
s3 := s3.New(auth, region)
bucket := s3.Bucket(u.BucketName())
// If the list doesn't return an error, then we've got our bucket
_, err = bucket.List("", "", "", 0)
if err != nil {
return errors.New("Could not find bucket `" + u.BucketName() + "` in region `" + region.Name + "` (" + err.Error() + ")")
}
u.Bucket = bucket
return nil
}
示例14: Run
func Run(command string, arg ...string) (string, error) {
output, err := exec.Command(command, arg...).Output()
if err != nil {
logger.Debug("Could not run: %s %s (returned %s) (%T: %v)", command, arg, output, err, err)
return "", err
}
return strings.Trim(fmt.Sprintf("%s", output), "\n"), nil
}
示例15: onUploadHeaderTime
func (r *JobRunner) onUploadHeaderTime(cursor int, total int, times map[string]string) {
retry.Do(func(s *retry.Stats) error {
logger.Debug("Uploading header times %d..%d (%d)", cursor+1, total, len(times))
_, err := r.APIClient.HeaderTimes.Save(r.Job.ID, &api.HeaderTimes{Times: times})
if err != nil {
logger.Warn("%s (%s)", err, s)
}
return err
}, &retry.Config{Maximum: 10, Interval: 1 * time.Second})
}