Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lock warpper for resource change. #294

Merged
merged 1 commit into from
Mar 24, 2021
Merged

Conversation

hannatao
Copy link
Member

No description provided.

@@ -148,6 +149,8 @@ func PopulateFailedResponse(cc *Context, err error, abort bool) {

// HandlerFunc HandlerFunc
type HandlerFunc func(c *Context) (interface{}, error)
type LockFunc func(ctx context.Context, name string) (string, error)
type UnlockFunc func(ctx context.Context, name, value string) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value 改成 version,好理解一些

func WrapperWithLock(lockFunc LockFunc, unlockFunc UnlockFunc) func(c *gin.Context) {
return func(c *gin.Context) {
cc := NewContext(c)
ctx := context.Background()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不考虑给超时时间嘛?

plugin/lock.go Outdated

// LockWithExpireTime lock the resource with expire time
// PARAMS:
// - name: the lock's name
// - expireTime(seconds): the expire time of the lock, if acquired the lock
// RETURNS:
// error: if has error else nil
LockWithExpireTime(name, value string, expireTime int64) error
LockWithExpireTime(ctx context.Context, name string, expireTime int64) (string, error)
Copy link
Contributor

@chensheng0 chensheng0 Mar 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx 来决定是否有超时时间,这俩接口留一个就行
Lock,一个接口

type LockerService interface {
Lock(ctx context.Context, name string) (string, error)
LockWithExpireTime(ctx context.Context, name string, expireTime int64) (string, error)
Unlock(ctx context.Context, name, value string) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

@codecov-io
Copy link

Codecov Report

Merging #294 (ea16c73) into master (a8a0adb) will decrease coverage by 0.04%.
The diff coverage is 34.78%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #294      +/-   ##
==========================================
- Coverage   66.46%   66.41%   -0.05%     
==========================================
  Files          81       82       +1     
  Lines        5976     5982       +6     
==========================================
+ Hits         3972     3973       +1     
- Misses       1461     1465       +4     
- Partials      543      544       +1     
Impacted Files Coverage Δ
common/context.go 73.60% <0.00%> (-5.04%) ⬇️
service/locker.go 0.00% <0.00%> (ø)
task/task.go 0.00% <0.00%> (ø)
api/api.go 58.82% <50.00%> (-0.56%) ⬇️
plugin/default/lock/empty_lock.go 80.00% <100.00%> (-3.34%) ⬇️
server/admin_server.go 84.14% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8a0adb...ea16c73. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants