MCPcopy
hub / github.com/crowdsecurity/crowdsec / AcquireLock

Method AcquireLock

pkg/database/lock.go:19–35  ·  view source on GitHub ↗
(ctx context.Context, name string)

Source from the content-addressed store, hash-verified

17)
18
19func (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
37func (c *Client) ReleaseLock(ctx context.Context, name string) error {
38 log.Debugf("releasing lock %s", name)

Callers 1

AcquirePullCAPILockMethod · 0.95

Calls 5

IsConstraintErrorFunction · 0.92
SaveMethod · 0.45
SetCreatedAtMethod · 0.45
SetNameMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected