func (db *BoltJobDB) GetAll() ([]*job.Job, error) { allJobs := []*job.Job{} err := db.dbConn.Update(func(tx *bolt.Tx) error { bucket, err := tx.CreateBucketIfNotExists(jobBucket) if err != nil { return err } err = bucket.ForEach(func(k, v []byte) error { buffer := bytes.NewBuffer(v) dec := gob.NewDecoder(buffer) j := new(job.Job) err := dec.Decode(j) if err != nil { return err } err = j.InitDelayDuration(false) if err != nil { return err } allJobs = append(allJobs, j) return nil }) return err }) return allJobs, err }
// Save persists a Job. func (d DB) Save(j *job.Job) error { bytes, err := j.Bytes() if err != nil { return err } _, err = d.conn.Do("HSET", HashKey, j.Id, bytes) if err != nil { return err } return nil }
func (db *BoltJobDB) Get(id string) (*job.Job, error) { j := new(job.Job) err := db.dbConn.View(func(tx *bolt.Tx) error { b := tx.Bucket(jobBucket) v := b.Get([]byte(id)) if v == nil { return job.ErrJobNotFound(id) } buf := bytes.NewBuffer(v) err := gob.NewDecoder(buf).Decode(j) return err }) if err != nil { return nil, err } j.Id = id return j, nil }