Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/nokka/go-scheduler

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/nokka/go-scheduler

  • v1.0.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

Go scheduler

Go scheduler lets you put work on a queue that will perform the job given when there's a free worker in the worker pool.

Missing things
  • Handling panics
Examples

Examples can be found here as well.

// Job implements the Performer interface.
type Job struct {
	Name    string
	Payload []int
}

// Run performs the given work.
func (j Job) Run() {
	time.Sleep(1 * time.Second)
	fmt.Printf("Performing job with name %s\n", j.Name)
	fmt.Printf("Payload was %v\n", j.Payload)
}

func main() {
	var (
		maxWorkers   = 5
		maxQueueSize = 100
	)

	// Channel to receive errors on.
	errors := make(chan error)

	// Create the job queue we'll use through the dispatcher.
	queue := make(chan job.Performer, *maxQueueSize)

	// Create the scheduler, that will keep track of all jobs.
	scheduler := scheduler.New(queue, *maxWorkers)

	// Start the scheduler.
	scheduler.Run()

	// Create 10 jobs, and let it go through the queue.
	for i := 0; i < 10; i++ {
		// Create a job.
		job := Job{Name: fmt.Sprintf("job-%d", i), Payload: []int{0, 1, 2}}

		// Queue the job on our work queue.
		queue <- job
	}

	// Capture interrupts.
	go func() {
		c := make(chan os.Signal)
		signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
		errors <- fmt.Errorf("Got signal: %s", <-c)
	}()

	if err := <-errors; err != nil {
		log.Printf("Got error: %+v\n", err)
	}

	log.Println("terminated")
}

FAQs

Package last updated on 22 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc