Skip to content

nozo-moto/taskqueue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task_Queue

build

This is task queue worker. I create referencing TaskQueue of GCP. You can set task's interval time, and retry count.

How To Use

  1. Add task to goroutine worker.
  2. Run Task in goroutine worker. If error happen, task will be retried as many times as retry count.

Sample Code

// set task queue interval
taskQueue := taskqueue.New(100 * time.Millisecond)
defer taskQueue.Stop()
// Run Task Queue Job in background.
go taskQueue.Run()

// Add Task, you can set retry coun
// if taskQueue.Stop called taskQueue.Add return err
err := taskQueue.Add(
	func(args ...interface{}) error {
        // Get Agument
		index, ok := args[0].([]interface{})[0].(int)
		if !ok {
			panic("error assation not good")
		}
		fmt.Printf("hoge %d\n", index)

		return nil
	},
	3, // Retry Count
	index, // Argument
)

About

Golang Queueing Worker like google TaskQueue

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages