Пример #1
0
/*
Creates and returns a new Context object. Because some
items are absolutely required by this object and the processes
that use it, this method will panic if it gets an invalid
config param from the command line, or if it cannot set up some
essential services, such as logging.

This object is meant to used as a singleton with any of the
stand-along processing services (bag_processor, bag_restorer,
cleanup, etc.).
*/
func NewContext(config *models.Config) (context *Context) {
	context = &Context{
		succeeded: int64(0),
		failed:    int64(0),
	}
	context.Config = config
	context.MessageLog, context.pathToLogFile = logger.InitLogger(config)
	context.JsonLog, context.pathToJsonLog = logger.InitJsonLogger(config)
	context.VolumeClient = network.NewVolumeClient(context.Config.VolumeServicePort)
	context.NSQClient = network.NewNSQClient(context.Config.NsqdHttpAddress)
	context.initPharosClient()
	return context
}
Пример #2
0
func (reader *APTBucketReader) addToNSQ(workItem *models.WorkItem) {
	client := network.NewNSQClient(reader.Context.Config.NsqdHttpAddress)
	err := client.Enqueue(reader.Context.Config.FetchWorker.NsqTopic, workItem.Id)
	if err != nil {
		msg := fmt.Sprintf("Error sending WorkItem %d to NSQ: %v", workItem.Id, err)
		if reader.stats != nil {
			reader.stats.AddError(msg)
		}
		reader.Context.MessageLog.Error(msg)
		return
	}
	reader.Context.MessageLog.Info("Added WorkItem id %d to NSQ (%s/%s)",
		workItem.Id, workItem.Bucket, workItem.Name)
	if reader.stats != nil {
		reader.stats.AddWorkItem("WorkItemsQueued", workItem)
	}
	return
}