Categorygithub.com/jeayu/redischeduler
modulepackage
0.0.0-20210301074945-908dd7b27422
Repository: https://github.com/jeayu/redischeduler.git
Documentation: pkg.go.dev

# README

Redischeduler Build Status Coverage Status

Redischeduler is a distributed job scheduler written in Go.

Installation

go get github.com/jeayu/redischeduler

Getting Started

Creating scheduler

  • To create partitions, you need to configure the total partition size and the sharding for each partition
// the total partition size.
partitionSize := 2
// the sharding for each partition.
clientOptions := []*redis.Options{
    // partition 1
    {
        Addr: "localhost:6379",
        DB:   1,
    },
    // partition 2
    {
        Addr: "localhost:6379",
        DB:   1,
    },
}
partitionRedisConfigs := NewSchedulerPartitionRedisConfigs(clientOptions, partitionSize)
clients := NewPartitionRedisSlice(partitionRedisConfigs)
// creating partitions
partitions := NewPartitions(partitionSize, clients)
  • To create scheduler
scheduler := NewPartitionScheduler(partitions, nil, nil)
  • Schedule task
task := NewTask("SayHi", "world")
duration := 3 * time.Second
scheduler.ScheduleTask(task, duration)

Creating worker

  • To create a task worker, you need to define a task invoker and and create the partition in which the worker
partitionId := 1
partitionSize := 2
clientOptions := []*redis.Options{
     // partition 1
    {
        Addr: "localhost:6379",
        DB:   1,
    },
}
worker, err := NewSinglePartitionWorker(&SinglePartitionWorkerConfig{
    PartitionId:          partitionId,
    PartitionSize:        partitionSize,
    PartitionRedisConfig: NewPartitionRedisConfigs(clientOptions, partitionId),
    TaskInvoker: &TaskInvoker{
        Functions: map[string]reflect.Value{
            "SayHi": reflect.ValueOf(sayHi),
            "Say":   reflect.ValueOf(say),
        },
    },
})
  • Running worker
worker.Run()

# Functions

No description provided by the author
No description provided by the author
ClientOptions: Redis configuration of sharding PartitionShards: number of shards per partition PartitionId range: [StartPartition, ...] Sharding range: [StartSharding, ...].
No description provided by the author
No description provided by the author
Initialize all partitions.
No description provided by the author
No description provided by the author
Initialize single partition.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Returns the shardingId Returns value range: [StartSharding, Size * PartitionShards] Note: The sharding parameter is greater than or equal to the constant StartSharding.

# Constants

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
-----------------------------------------.
-----------------------------------------.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author