(ctx context.Context, name string)
| 17 | ) |
| 18 | |
| 19 | func (c *Client) AcquireLock(ctx context.Context, name string) error { |
| 20 | log.Debugf("acquiring lock %s", name) |
| 21 | _, err := c.Ent.Lock.Create(). |
| 22 | SetName(name). |
| 23 | SetCreatedAt(time.Now().UTC()). |
| 24 | Save(ctx) |
| 25 | |
| 26 | if ent.IsConstraintError(err) { |
| 27 | return err |
| 28 | } |
| 29 | |
| 30 | if err != nil { |
| 31 | return fmt.Errorf("insert lock: %w: %w", err, InsertFail) |
| 32 | } |
| 33 | |
| 34 | return nil |
| 35 | } |
| 36 | |
| 37 | func (c *Client) ReleaseLock(ctx context.Context, name string) error { |
| 38 | log.Debugf("releasing lock %s", name) |
no test coverage detected