Beispiel #1
0
func Foobar(job worker.Job) ([]byte, error) {
	log.Printf("Foobar: Data=[%s]\n", job.Data())
	for i := 0; i < 10; i++ {
		job.SendWarning([]byte{byte(i)})
		job.SendData([]byte{byte(i)})
		job.UpdateStatus(i+1, 100)
	}
	return job.Data(), nil
}
Beispiel #2
0
func caffePlotTask(job worker.Job) (data []byte, err error) {
	suffix := string(job.Data())

	if err = run(PLOT_ROOT+"/parse_log.sh", LOG_DIR+"/caffe.INFO"); err != nil {
		log.Printf("Error: %s\n", err)
		return
	}

	if err = run("gnuplot", PLOT_ROOT+"/plot_log.gnuplot."+suffix); err != nil {
		log.Printf("Error: %s\n", err)
		return
	}
	data, err = ioutil.ReadFile("/tmp/" + suffix + ".png")
	return
}
Beispiel #3
0
func DbUpsert(job worker.Job) ([]byte, error) {
	// a gearman wrapper for UpsertDocument
	dbhelp.Log(0, "Database upserter called!")
	var data DbData
	if err := bson.Unmarshal(job.Data(), &data); err != nil {
		dbhelp.Log(2, err.Error())
		return nil, err
	}
	if !dbhelp.CorrectKey(data.Key) {
		dbhelp.Log(2, "Secret key mismatch")
		b, _ := bson.Marshal(bson.M{"status": "error", "description": "Secret key mismatch"})
		return b, job.Err()
	}
	url := dbhelp.GetURL()
	response, err := UpsertDocument(url, data.Database, data.Collection, data.Data)
	if err != nil {
		dbhelp.Log(1, err.Error())
		job.SendWarning([]byte("\"error\":\"" + err.Error() + "\""))
	}
	err = job.Err()
	return response, err
}
Beispiel #4
0
func (g GearmanWorker) handelJob(job worker.Job) ([]byte, error) {
	secret := job.Data()
	if g.aesECBDecrypter != nil {
		var err error
		secret, err = g.aesECBDecrypter.Decypt(secret)
		if err != nil {
			g.log.Warn(err, ". Data: ", string(job.Data()))
			return job.Data(), nil
		}
	}
	splittedPerformanceData := helper.StringToMap(string(secret), "\t", "::")
	g.log.Debug("[ModGearman] ", string(job.Data()))
	g.log.Debug("[ModGearman] ", splittedPerformanceData)
	for singlePerfdata := range g.nagiosSpoolfileWorker.PerformanceDataIterator(splittedPerformanceData) {
		for _, r := range g.results {
			select {
			case r <- singlePerfdata:
			case <-time.After(time.Duration(1) * time.Minute):
				logging.GetLogger().Warn("GearmanWorker: Could not write to buffer")
			}
		}
	}
	return job.Data(), nil
}
Beispiel #5
0
func ToUpperDelay10(job worker.Job) ([]byte, error) {
	log.Printf("ToUpper: Data=[%s]\n", job.Data())
	time.Sleep(10 * time.Second)
	data := []byte(strings.ToUpper(string(job.Data())))
	return data, nil
}
Beispiel #6
0
func ToUpper(job worker.Job) ([]byte, error) {
	log.Printf("ToUpper: Data=[%s]\n", job.Data())
	data := []byte(strings.ToUpper(string(job.Data())))
	return data, nil
}