Esempio n. 1
0
func (j *Jobsms) Run() {
	for {
		Utils.LogInfo("Jobsms delay %d Second", Config.GetLoopTime().Sms)
		time.Sleep(time.Second * Config.GetLoopTime().Sms)

		beanstalkd, err := lentil.Dial(Config.GetBeanstalk().Server)
		if err != nil {
			Utils.LogPanicErr(err)
		} else {
			err = beanstalkd.Use(Config.GetBeanstalk().MobileQueue)
		}

		if err != nil {
			Utils.LogPanicErr(err)
		} else {
			for i := 0; i < 10; i++ {
				job, err := beanstalkd.PeekReady()
				if err != nil {
					//Utils.LogPanicErr(err)
					break
				} else {
					body := strings.SplitN(string(job.Body), "\t", 2)
					if len(body) == 2 {
						r, err := base64.StdEncoding.DecodeString(body[1])
						if err == nil {
							fmt.Printf("Job id: %d  \nmobile: %s \nbody: %s", job.Id, body[0], string(r))
							e := SendSms(body[0], string(r))
							if e != nil {
								Utils.LogPanicErr(e)
							}
						}
					}
					beanstalkd.Delete(job.Id)
				}
			}
		}

	}
}
Esempio n. 2
0
func (j *Jobmail) Run() {
	for {

		Utils.LogInfo("Jobmail delay %d Second", Config.GetLoopTime().Mail)
		time.Sleep(time.Second * Config.GetLoopTime().Mail)
		beanstalkd, err := lentil.Dial(Config.GetBeanstalk().Server)
		if err != nil {
			Utils.LogPanicErr(err)
		} else {
			err = beanstalkd.Use(Config.GetBeanstalk().MailQueue)
		}
		if err != nil {
			Utils.LogPanicErr(err)
		} else {
			for i := 0; i < 10; i++ {
				job, err := beanstalkd.PeekReady()
				if err != nil {
					//Utils.LogPanicErr(err)
					break
				} else {
					body := strings.SplitN(string(job.Body), "\t", 4)
					if len(body) == 4 {
						r, err := base64.StdEncoding.DecodeString(body[3])
						if err == nil {
							fmt.Printf("Job id: %d  \nmail to:%s \nsubject:%s\nbody: , %s", job.Id, body[0], body[1], string(r))
							//SendMail( body[0], body[1], string(r), body[2])
							SendMailBySohu(body[0], body[1], string(r))
						}
					}
					beanstalkd.Delete(job.Id)
				}
			}
		}

	}
}