示例#1
0
func upload() {
	for {
		select {
		case do := <-uploadSet:
			sec := do.LogTime.Unix()
			sec = sec - sec%300 - 600
			logtime := time.Unix(sec, 0).Format("2006-01-02T15:04:00.000+0800")
			options.Log.Noticef("开始上传域名为[%v]时间点为[%v]的日志文件", do.Host, logtime)
			if err := options.Upload(
				do.FtpLogFile,
				do.LocalLogFile,
				do.FtpFinishFile,
				do.LocalFinishFile,
				do.FtpDir,
				do.Host,
				options.Config.Custom,
			); err != nil {
				options.Log.Errorf("上传域名为[%v]时间点为[%v]的日志文件失败,失败原因:%v", do.Host, logtime, err)
				reuploadSet <- do
			} else {
				options.Log.Noticef("上传域名为[%v]时间点为[%v]的日志文件成功", do.Host, logtime)
			}
		}
	}
}
示例#2
0
func Reupload() {
	for {
		select {
		case redo := <-reuploadSet:
			time.Sleep(time.Second * 30)
			sec := redo.LogTime.Unix()
			sec = sec - sec%300 - 600
			logtime := time.Unix(sec, 0).Format("2006-01-02T15:04:00.000+0800")
			options.Log.Noticef("开始重传域名为[%v]时间点为[%v]的日志文件", redo.Host, logtime)

			if options.Config.Custom == "mangguo" {
				if err := options.PostFileInfo(redo.File, options.Config.MongguoPostFileUrl); err != nil {
					options.Log.Error(err)
					redo.RetryNum += 1
					reuploadSet <- redo
					continue
				} else {
					if err := options.CreateFinishFile(redo.LocalFinishFile); err != nil {
						options.Log.Errorf("重传时创建日志完成文件[%v]失败,错误原因:%v", redo.LocalFinishFile, err)
						redo.RetryNum += 1
						reuploadSet <- redo
						continue
					}
				}
				if err := options.CreateFinishFile(redo.LocalFinishFile); err != nil {
					options.Log.Errorf("重传时创建日志完成文件[%v]失败,错误原因:%v", redo.LocalFinishFile, err)
					redo.RetryNum += 1
					reuploadSet <- redo
					continue
				}
			}

			if redo.RetryNum < 4 {
				if err := options.Upload(
					redo.FtpLogFile,
					redo.LocalLogFile,
					redo.FtpFinishFile,
					redo.LocalFinishFile,
					redo.FtpDir,
					redo.Host,
					options.Config.Custom,
				); err != nil {
					options.Log.Errorf("上传域名为[%v]时间点为[%v]的日志文件失败,失败原因:%v", redo.Host, logtime, err)
					redo.RetryNum += 1
					reuploadSet <- redo
				} else {
					options.Log.Noticef("重传域名为[%v]时间点为[%v]的日志文件成功", redo.Host, logtime)
				}
			} else {
				options.Log.Warningf("域名为[%v]时间点为[%v]的日志文件重传次数已经超过[3]次,不会再重传", logtime)
			}
		}
	}
}