Exemple #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
}
Exemple #2
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
}