taskqueue

package
v0.0.131 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2023, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var (
	TaskQueue_QueueType_name = map[int32]string{
		0: "queue_type_redis",
	}
	TaskQueue_QueueType_value = map[string]int32{
		"queue_type_redis": 0,
	}
)

Enum value maps for TaskQueue_QueueType.

View Source
var File_pkg_pool_taskqueue_taskqueue_proto protoreflect.FileDescriptor

Functions

func Register

func Register(b Tasker)

Register registers the tasker to the tasker map. b.Name will be used as the name registered with this builder.

Types

type CompletedConfig

type CompletedConfig struct {
	// contains filtered or unexported fields
}

func (CompletedConfig) New

func (c CompletedConfig) New(ctx context.Context, opts ...PoolOption) (*Pool, error)

type Config

type Config struct {
	Proto TaskQueue
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(options ...ConfigOption) *Config

func (*Config) ApplyOptions

func (o *Config) ApplyOptions(options ...ConfigOption) *Config

func (*Config) Complete

func (c *Config) Complete() CompletedConfig

Complete set default ServerRunOptions.

type ConfigOption

type ConfigOption interface {
	// contains filtered or unexported methods
}

A ConfigOption sets options.

func WithViper

func WithViper(v *viper.Viper) ConfigOption

type ConfigOptionFunc

type ConfigOptionFunc func(*Config)

ConfigOptionFunc wraps a function that modifies Client into an implementation of the ConfigOption interface.

type EmptyConfigOption

type EmptyConfigOption struct{}

EmptyConfigOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyPoolOption

type EmptyPoolOption struct{}

EmptyPoolUrlOption does not alter the Pooluration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool(taskq queue_.Queue, opts ...PoolOption) *Pool

func (*Pool) ApplyOptions

func (o *Pool) ApplyOptions(options ...PoolOption) *Pool

func (*Pool) Consume

func (p *Pool) Consume(ctx context.Context) (err error)

func (*Pool) FetchResult

func (p *Pool) FetchResult(ctx context.Context, key string) (*queue_.MessageResult, error)

func (*Pool) Publish

func (p *Pool) Publish(ctx context.Context, msg *queue_.Message) (string, error)

func (*Pool) Work

func (p *Pool) Work(ctx context.Context, msg *queue_.Message) error

type PoolOption

type PoolOption interface {
	// contains filtered or unexported methods
}

A PoolOption sets options.

func WithFetchTimeout

func WithFetchTimeout(timeout time.Duration) PoolOption

func WithFetcherBurst

func WithFetcherBurst(burst uint32) PoolOption

func WithResultCallbackFunc

func WithResultCallbackFunc(callback queue_.ResultCallbackFunc) PoolOption

func WithResultExpired

func WithResultExpired(resultExpired time.Duration) PoolOption

func WithWorkTimeout

func WithWorkTimeout(timeout time.Duration) PoolOption

func WithWorkerBurst

func WithWorkerBurst(burst uint32) PoolOption

type PoolOptionFunc

type PoolOptionFunc func(*Pool)

PoolOptionFunc wraps a function that modifies Pool into an implementation of the PoolOption interface.

type PoolOptions

type PoolOptions struct {
	// contains filtered or unexported fields
}

type Task

type Task struct {
	// contains filtered or unexported fields
}

type TaskOptions

type TaskOptions struct {
	Name string
}

type TaskQueue

type TaskQueue struct {
	Enabled       bool                `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"`
	WorkerBurst   uint32              `protobuf:"varint,2,opt,name=worker_burst,json=workerBurst,proto3" json:"worker_burst,omitempty"`
	FetcherBurst  uint32              `protobuf:"varint,3,opt,name=fetcher_burst,json=fetcherBurst,proto3" json:"fetcher_burst,omitempty"`
	WorkTimeout   *duration.Duration  `protobuf:"bytes,4,opt,name=work_timeout,json=workTimeout,proto3" json:"work_timeout,omitempty"`
	FetchTimeout  *duration.Duration  `protobuf:"bytes,5,opt,name=fetch_timeout,json=fetchTimeout,proto3" json:"fetch_timeout,omitempty"`
	ResultExpired *duration.Duration  `protobuf:"bytes,6,opt,name=result_expired,json=resultExpired,proto3" json:"result_expired,omitempty"`
	QueueType     TaskQueue_QueueType `` /* 136-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*TaskQueue) Descriptor deprecated

func (*TaskQueue) Descriptor() ([]byte, []int)

Deprecated: Use TaskQueue.ProtoReflect.Descriptor instead.

func (*TaskQueue) GetEnabled

func (x *TaskQueue) GetEnabled() bool

func (*TaskQueue) GetFetchTimeout

func (x *TaskQueue) GetFetchTimeout() *duration.Duration

func (*TaskQueue) GetFetcherBurst

func (x *TaskQueue) GetFetcherBurst() uint32

func (*TaskQueue) GetQueueType

func (x *TaskQueue) GetQueueType() TaskQueue_QueueType

func (*TaskQueue) GetResultExpired

func (x *TaskQueue) GetResultExpired() *duration.Duration

func (*TaskQueue) GetWorkTimeout

func (x *TaskQueue) GetWorkTimeout() *duration.Duration

func (*TaskQueue) GetWorkerBurst

func (x *TaskQueue) GetWorkerBurst() uint32

func (*TaskQueue) ProtoMessage

func (*TaskQueue) ProtoMessage()

func (*TaskQueue) ProtoReflect

func (x *TaskQueue) ProtoReflect() protoreflect.Message

func (*TaskQueue) Reset

func (x *TaskQueue) Reset()

func (*TaskQueue) String

func (x *TaskQueue) String() string

type TaskQueue_QueueType

type TaskQueue_QueueType int32
const (
	TaskQueue_queue_type_redis TaskQueue_QueueType = 0
)

func (TaskQueue_QueueType) Descriptor

func (TaskQueue_QueueType) Enum

func (TaskQueue_QueueType) EnumDescriptor deprecated

func (TaskQueue_QueueType) EnumDescriptor() ([]byte, []int)

Deprecated: Use TaskQueue_QueueType.Descriptor instead.

func (TaskQueue_QueueType) Number

func (TaskQueue_QueueType) String

func (x TaskQueue_QueueType) String() string

func (TaskQueue_QueueType) Type

type Tasker

type Tasker interface {
	TaskHandler(ctx context.Context, message *queue_.Message) (*queue_.MessageResult, error)
	Scheme() string
}

func Get

func Get(scheme string) Tasker

Get returns the tasker registered with the given scheme.

If no tasker is register with the scheme, nil will be returned.

type TaskerMap

type TaskerMap sync.Map

func (*TaskerMap) Delete

func (m *TaskerMap) Delete(key string)

Delete deletes the value for a key.

func (*TaskerMap) Load

func (m *TaskerMap) Load(key string) (Tasker, bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*TaskerMap) LoadAndDelete

func (m *TaskerMap) LoadAndDelete(key string) (value Tasker, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*TaskerMap) LoadOrStore

func (m *TaskerMap) LoadOrStore(key string, value Tasker) (Tasker, bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*TaskerMap) Range

func (m *TaskerMap) Range(f func(key string, value Tasker) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call.

Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.

func (*TaskerMap) Store

func (m *TaskerMap) Store(key string, value Tasker)

Store sets the value for a key.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL