当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Errorf方法代码示例

本文整理汇总了Golang中github.com/zeebo/goci/app/httputil.Context.Errorf方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Errorf方法的具体用法?Golang Context.Errorf怎么用?Golang Context.Errorf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/zeebo/goci/app/httputil.Context的用法示例。


在下文中一共展示了Context.Errorf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: sendJabberNotification

func sendJabberNotification(ctx httputil.Context, u string, test entities.TestResult) (err error) {
	//exit early if we have no url
	if u == "" {
		return
	}

	//make sure we have configuration values
	if Config.Username == "" || Config.Domain == "" || Config.Password == "" {
		ctx.Errorf("Unable to send notification (%s): configuration not specified", test.ImportPath)
		return
	}

	ctx.Infof("Send jabber notification (%s): %s", test.ImportPath, u)

	//open a tcp connection to the jabber server
	netConn, err := net.Dial("tcp", "talk.google.com:5222")
	if err != nil {
		return
	}
	defer netConn.Close()

	//use that connection in the xmpp config and dial out
	config := &xmpp.Config{Conn: netConn}
	conn, err := xmpp.Dial("", Config.Username, Config.Domain, Config.Password, config)
	if err != nil {
		return
	}

	//send off the message
	message := fmt.Sprintf("%s @ %s status is now %s", test.ImportPath, test.Revision, test.Status)
	err = conn.Send(u, message)
	return
}
开发者ID:kleopatra999,项目名称:goci,代码行数:33,代码来源:notifications.go

示例2: dispatchWork

//dispatchWork is the handler that gets called for a queue item. It grabs a builder
//and runner and dispatches the work item to them, recoding when that operation
//started.
func dispatchWork(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
	//find all the documents that are waiting or (processing and their attempt is
	//taking too long)
	type L []interface{}
	selector := bson.M{
		"$or": L{
			bson.M{"status": entities.WorkStatusWaiting},
			bson.M{
				"status":            entities.WorkStatusProcessing,
				"attemptlog.0.when": bson.M{"$lt": time.Now().Add(-1 * attemptTime)},
			},
		},
	}
	iter := ctx.DB.C("Work").Find(selector).Iter()

	var work entities.Work
	for iter.Next(&work) {
		//if its a processing task with too many attempts, store it as a dispatch
		//error.
		if len(work.AttemptLog) >= maxAttempts {
			ctx.Infof("Work item %s had too many attempts", work.ID)
			args := &rpc.DispatchResponse{
				Key:     work.ID.Hex(),
				Error:   "Unable to complete Work item. Too many failed attempts.",
				WorkRev: work.Revision,
			}

			//send it off to the response rpc
			respUrl := httputil.Absolute(router.Lookup("Response"))
			cl := client.New(respUrl, http.DefaultClient, client.JsonCodec)
			if err := cl.Call("Response.DispatchError", args, new(rpc.None)); err != nil {
				ctx.Infof("Couldn't store a dispatch error for work item %s: %s", work.ID, err)
			}

			continue
		}

		//attempt to dispatch the work item
		err := dispatchWorkItem(ctx, work)
		if err != nil {
			ctx.Errorf("Error dispatching work: %s", err)
		}
	}

	//check for errors running the iteration
	if err := iter.Err(); err != nil {
		ctx.Errorf("Error iterating over work items: %s", err)
		e = httputil.Errorf(err, "Error iterating over work items")
		return
	}

	return
}
开发者ID:kleopatra999,项目名称:goci,代码行数:56,代码来源:queue.go

示例3: dispatchNotifications

func dispatchNotifications(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
	//find all documents that are waiting or (processing and their attempt is
	//taking too long)
	type L []interface{}
	selector := bson.M{
		"$or": L{
			bson.M{"status": entities.NotifStatusWaiting},
			bson.M{
				"status":            entities.NotifStatusProcessing,
				"attemptlog.0.when": bson.M{"$lt": time.Now().Add(-1 * attemptTime)},
			},
		},
	}
	iter := ctx.DB.C("Notification").Find(selector).Iter()

	var n entities.Notification
	for iter.Next(&n) {
		//if it's processing with too may attempts then just give up
		if len(n.AttemptLog) >= maxAttempts {
			ctx.Infof("Notification %s had too many attempts", n.ID)

			ops := []txn.Op{{
				C:  "Notification",
				Id: n.ID,
				Assert: bson.M{
					"status":   entities.NotifStatusProcessing,
					"revision": n.Revision,
				},
				Update: bson.M{
					"$set": bson.M{"status": entities.NotifStatusError},
					"$inc": bson.M{"revision": 1},
				},
			}}

			//try to update the notification
			err := ctx.R.Run(ops, bson.NewObjectId(), nil)
			if err == txn.ErrAborted {
				ctx.Infof("Lost race updating notification %s", n.ID)
				err = nil
			}
			if err != nil {
				ctx.Errorf("Error updating notification %s: %s", n.ID, err)
			}

			continue
		}

		err := dispatchNotificationItem(ctx, &n)
		if err != nil {
			ctx.Errorf("Error processing notification %s: %s", n.ID, err)
			continue
		}

		//update the thing as being done
		ops := []txn.Op{{
			C:  "Notification",
			Id: n.ID,
			Assert: bson.M{
				"revision": n.Revision,
			},
			Update: bson.M{
				"$inc": bson.M{"revision": 1},
				"$set": bson.M{"status": entities.NotifStatusCompleted},
			},
		}}

		err = ctx.R.Run(ops, bson.NewObjectId(), nil)
		if err == txn.ErrAborted {
			ctx.Infof("Lost the race setting the notification %s to complete", n.ID)
			err = nil
		}
		if err != nil {
			ctx.Errorf("Error setting notification %s to complete: %s", n.ID, err)
		}
	}

	//check for errors in the iteration
	if err := iter.Err(); err != nil {
		ctx.Errorf("Error iterating over notifications: %s", err)
		e = httputil.Errorf(err, "Error iterating over notifications")
		return
	}

	return
}
开发者ID:kleopatra999,项目名称:goci,代码行数:85,代码来源:notifications.go


注:本文中的github.com/zeebo/goci/app/httputil.Context.Errorf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。