1234567891011121314151617181920212223242526272829303132333435363738 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package transtasker
- import "gorm.io/gorm"
- // PlainTask 普通任务,即本身不支持事务的任务,如redis/es
- type PlainTask struct {
- exec Task
- rollback Task
- }
- // Exec 普通任务执行
- func (p *PlainTask) Exec(db *gorm.DB) error {
- if p.exec != nil {
- return p.exec(db)
- }
- return nil
- }
- // Rollback 普通任务回滚
- func (p *PlainTask) Rollback(db *gorm.DB) error {
- if p.rollback != nil {
- return p.rollback(db)
- }
- return nil
- }
- // NewPlainTask 新建一个普通任务
- func NewPlainTask(exec Task, rollback Task) Tasker {
- return &PlainTask{
- exec: exec,
- rollback: rollback,
- }
- }
|