dbconnector

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 14 Imported by: 3

README

db-connector

A jobworker connector with database for go-jwdk/jobworker package.

Supported databases:

  • MySQL
  • Postgres
  • SQLite3

Requirements

Go 1.13+

Installation

This package can be installed with the go get command:

$ go get -u github.com/go-jwdk/db-connector

Usage

MySQL:

import "github.com/go-jwdk/jobworker"
import _ "github.com/go-jwdk/db-connector/mysql"

conn, err := jobworker.Open("mysql", map[string]interface{}{
    "DSN":             "user:password@/dbname",
    "MaxOpenConns":    3,
    "MaxMaxIdleConns": 3,
    "ConnMaxLifetime": time.Minute,
    "NumMaxRetries":   3,
})

Postgres:

import "github.com/go-jwdk/jobworker"
import _ "github.com/go-jwdk/db-connector/postgres"

conn, err := jobworker.Open("postgres", map[string]interface{}{
    "DSN":             "user=pqgotest dbname=pqgotest sslmode=verify-full",
    "MaxOpenConns":    3,
    "MaxMaxIdleConns": 3,
    "ConnMaxLifetime": time.Minute,
    "NumMaxRetries":   3,
})

SQLite3:

import "github.com/go-jwdk/jobworker"
import _ "github.com/go-jwdk/db-connector/sqlite3"

conn, err := jobworker.Open("sqlite3", map[string]interface{}{
    "DSN":             "file:test.db?cache=shared&mode=memory",
    "MaxOpenConns":    3,
    "MaxMaxIdleConns": 3,
    "ConnMaxLifetime": time.Minute,
    "NumMaxRetries":   3,
})

Documentation

Index

Constants

View Source
const (
	TablePrefix = "jwdk"
)

Variables

View Source
var ErrCompletedSubscription = errors.New("subscription is unsubscribed")
View Source
var (
	ErrNotFoundQueue = fmt.Errorf("not found queue")
)

Functions

This section is empty.

Types

type ChangeJobVisibilityInput

type ChangeJobVisibilityInput struct {
	Job               *jobworker.Job
	VisibilityTimeout int64
}

type ChangeJobVisibilityOutput

type ChangeJobVisibilityOutput struct{}

type Config

type Config struct {
	Name                  string
	DB                    *sql.DB
	NumMaxRetries         int
	QueueAttributesExpire time.Duration

	SQLTemplate        SQLTemplate
	IsUniqueViolation  func(err error) bool
	IsDeadlockDetected func(err error) bool
}

type Connector

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

func Open

func Open(cfg *Config) (*Connector, error)

func (*Connector) ChangeJobVisibility

func (c *Connector) ChangeJobVisibility(ctx context.Context, input *ChangeJobVisibilityInput) (*ChangeJobVisibilityOutput, error)

func (*Connector) Close

func (c *Connector) Close() error

func (*Connector) CompleteJob

func (*Connector) CreateQueue

func (c *Connector) CreateQueue(ctx context.Context, input *CreateQueueInput) (*CreateQueueOutput, error)

func (*Connector) DeleteJobBatch

func (c *Connector) DeleteJobBatch(ctx context.Context, input *DeleteJobBatchInput) (*DeleteJobBatchOutput, error)

func (*Connector) Enqueue

func (*Connector) EnqueueBatch

func (*Connector) FailJob

func (*Connector) GetQueueAttributes

func (c *Connector) GetQueueAttributes(ctx context.Context, input *GetQueueAttributesInput) (*GetQueueAttributesOutput, error)

func (*Connector) GrabJobs

func (c *Connector) GrabJobs(ctx context.Context, input *GrabJobsInput) (*GrabJobsOutput, error)

func (*Connector) MoveJobBatch

func (c *Connector) MoveJobBatch(ctx context.Context, input *MoveJobBatchInput) (*MoveJobBatchOutput, error)

func (*Connector) Name

func (c *Connector) Name() string

func (*Connector) SetLoggerFunc

func (c *Connector) SetLoggerFunc(f jobworker.LoggerFunc)

func (*Connector) SetQueueAttributes

func (c *Connector) SetQueueAttributes(ctx context.Context, input *SetQueueAttributesInput) (*SetQueueAttributesOutput, error)

func (*Connector) Subscribe

type CreateQueueInput

type CreateQueueInput struct {
	Name              string
	DelaySeconds      int64
	VisibilityTimeout int64
	MaxReceiveCount   int64
	DeadLetterTarget  string
}

type CreateQueueOutput

type CreateQueueOutput struct{}

type DeleteJobBatchInput

type DeleteJobBatchInput struct {
	Jobs []*jobworker.Job
}

type DeleteJobBatchOutput

type DeleteJobBatchOutput struct {
}

type GetQueueAttributesInput

type GetQueueAttributesInput struct {
	QueueName string
}

type GetQueueAttributesOutput

type GetQueueAttributesOutput struct {
	Attributes *QueueAttributes
}

type GrabJobsInput

type GrabJobsInput struct {
	QueueName         string
	MaxNumberOfJobs   int64
	VisibilityTimeout int64
}

type GrabJobsOutput

type GrabJobsOutput struct {
	Jobs []*jobworker.Job
}

type MoveJobBatchInput

type MoveJobBatchInput struct {
	Jobs []*jobworker.Job
	To   string
}

type MoveJobBatchOutput

type MoveJobBatchOutput struct {
}

type QueueAttributes

type QueueAttributes struct {
	Name              string
	RawName           string
	DelaySeconds      int64
	VisibilityTimeout int64
	MaxReceiveCount   int64 // If the value is zero, retry infinitely
	DeadLetterTarget  *string
}

func (QueueAttributes) HasDeadLetter

func (q QueueAttributes) HasDeadLetter() (string, bool)

type SQLTemplate added in v0.2.2

type SQLTemplate interface {
	NewFindJobDML(queueRawName string, jobID string) (string, []interface{})
	NewFindJobsDML(queueRawName string, limit int64) (string, []interface{})
	NewHideJobDML(queueRawName string, jobID string, oldReceiveCount, oldInvisibleUntil, invisibleTime int64) (string, []interface{})
	NewEnqueueJobDML(queueRawName, jobID, content string, deduplicationID, groupID *string, delaySeconds int64) (string, []interface{})
	NewEnqueueJobWithTimeDML(queueRawName, jobID, content string, deduplicationID, groupID *string, enqueueAt int64) (string, []interface{})
	NewDeleteJobDML(queueRawName, jobID string) (string, []interface{})
	NewUpdateJobByVisibilityTimeoutDML(queueRawName string, jobID string, visibilityTimeout int64) (string, []interface{})
	NewAddQueueAttributesDML(queueName, queueRawName string, delaySeconds, maxReceiveCount, visibilityTimeout int64, deadLetterTarget *string) (string, []interface{})
	NewUpdateQueueAttributesDML(queueRawName string, visibilityTimeout, delaySeconds, maxReceiveCount *int64, deadLetterTarget *string) (string, []interface{})
	NewFindQueueAttributesDML(queueName string) (string, []interface{})
	NewCreateQueueAttributesDDL() string
	NewCreateQueueDDL(queueRawName string) string
}

type SetQueueAttributesInput

type SetQueueAttributesInput struct {
	QueueName         string
	DelaySeconds      *int64
	VisibilityTimeout *int64
	MaxReceiveCount   *int64
	DeadLetterTarget  *string
}

type SetQueueAttributesOutput

type SetQueueAttributesOutput struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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