Esempio n. 1
0
func bind2Task(p *revel.Params, t *models.Task) (err error) {
	p.Bind(&t.Subject, "subject")
	p.Bind(&t.Content, "content")
	p.Bind(&t.Recipient, "recipient")
	p.Bind(&t.SendTime, "sendtime")
	p.Bind(&t.SendType, "sendtype")
	if t.SendType == "" && (t.SendType != "notice" || t.SendType != "fanout") {
		t.SendType = "fanout"
	}
	t.Type = "email"
	t.Created_At = time.Now()
	t.Recipient = strings.Trim(t.Recipient, ", ")
	return
}
Esempio n. 2
0
func dispatch_task(ch *amqp.Channel, d amqp.Delivery) {
	t := new(models.Task)
	if err := Decode(d.Body, t); err != nil {
		Log.Warn("decode dispatch task err: %v", err)
	}

	if err := models.CreateTask(Session, t); err != nil {
		Log.Error("create task err: %v", err)
	}
	defer d.Ack(false)

	t.Channel = "HY"
	if err := Publish(EX_INCOMING, "send."+t.SendType, t); err != nil {
		Log.Error("dispatch task %s err: %v", t.SendType, err)
	}
}
Esempio n. 3
0
func Checkout(t *models.Task,
	successor func(ex, rk string, data interface{}) error) (err error) {
	if t.TaskId == "" {
		t.TaskId = models.GetTaskId()
	}
	/*
	   amount := t.Count()

	   var trans_id string
	   trans_id, err = utils.Transaction(t.EntId)
	   if err == nil {
	     Log.Debug("task %s has been counted as amount of %d.", t.TaskId, amount)
	     err = utils.Consume(t.EntId, trans_id, amount)
	     if err != nil {
	       return
	     }
	     err = successor(EX_INCOMING, RK_PLATFORM, t)
	     if err == nil {
	       return utils.Commit(t.EntId, trans_id)
	     }
	     Log.Error("successor err: %s", err.Error())
	     utils.Abort(t.EntId, trans_id)
	   }*/
	err = successor(EX_INCOMING, RK_PLATFORM, t)
	return
}