Esempio n. 1
0
func (u *User) AddJob(subject string, content []byte, sched schedule.MultiSchedule, next time.Time) (model.Job, error) {
	tx, err := u.con.con.Begin()
	if err != nil {
		return nil, err
	}

	insjob := tx.Stmt(u.con.stmt[qInsertJob])

	res, err := insjob.Exec(uint64(u.id), subject, content, next.Unix(), sched.String())
	if err != nil {
		tx.Rollback()
		return nil, err
	}

	_id, err := res.LastInsertId()
	if err != nil {
		tx.Rollback()
		return nil, err
	}

	if err := tx.Commit(); err != nil {
		return nil, err
	}

	return &Job{
		con:     u.con,
		id:      DBID(_id),
		user:    u.id,
		subject: subject,
		content: content,
		next:    next,
		sched:   sched,
	}, nil
}
Esempio n. 2
0
func (j *Job) SetSchedule(sched schedule.MultiSchedule) error {
	if _, err := j.con.stmt[qSetSchedule].Exec(sched.String(), uint64(j.id)); err != nil {
		return err
	}

	j.sched = sched
	return nil
}