Skip to content

Latest commit

 

History

History
37 lines (30 loc) · 888 Bytes

README.md

File metadata and controls

37 lines (30 loc) · 888 Bytes

Glacier 开发框架任务调度器分布式锁实现

目前支持 redis 实现。

import (
	"time"

	"github.com/go-redis/redis/v8"
	redisLock "github.com/mylxsw/distribute-locks/redis"
	"github.com/mylxsw/glacier/infra"
	"github.com/mylxsw/glacier/scheduler"
)

type Provider struct{}

func (Provider) Aggregates() []infra.Provider {
	return []infra.Provider{
		scheduler.Provider(
			func(cc infra.Resolver, creator scheduler.JobCreator) {
				// add your jobs here
			},
			scheduler.SetLockManagerOption(func(resolver infra.Resolver) scheduler.LockManagerBuilder {
				// get redis instance
				redisClient := resolver.MustGet(&redis.Client{}).(*redis.Client)
				return func(name string) scheduler.LockManager {
					// create redis lock
					return redisLock.New(redisClient, name, 10*time.Minute)
				}
			}),
		),
	}
}

func (Provider) Register(cc infra.Binder) {}