taskinator

package module
v0.0.0-...-fd2d984 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 4 Imported by: 0

README ¶

TASKINATOR 🤖

Welcome to the TASKINATOR! This package provides a robust utility in Golang that helps to set up and manage tasks that executes based on the duration specified by the user.

Key Features 📌

  1. Schedule multiple tasks with given name, schedule time, maximum retry count, retry delay, and action function.

  2. Robust automatic retry logic in place in case of task failures.

  3. The ability to execute multiple tasks concurrently.


How to Use 🚀

1. Get the package

go get -u github.com/kylix31/taskinator 

2. Import the package

In your Go file, import the tasksgenerator package.

import "github.com/kylix31/taskinator"

3. Usage

Create a Scheduler object using the NewScheduler function.

scheduler := tasksgenerator.NewScheduler()

Add tasks to the Scheduler using the AddTask method. The Task struct must include the following fields:

  • Name (string): Name of the Task
  • Schedule (time.Duration): Interval at which the task will be triggered - if nil will run forever
  • MaxRetries (int): Maximum number of retries that will be done before task is considered failed
  • RetryDelay (time.Duration): Delay before each retry
  • Action (func() error): Function to be performed by the Task
task := tasksgenerator.Task{
	Name: "Sample Task",
	Schedule: 5 * time.Second,
	MaxRetries: 3,
	RetryDelay: 2 * time.Second,
	Action: func() error {
		// your task code
	},
}

scheduler.AddTask(task)

Finally, start the Scheduler using the Start method where Duration is the total time throughout which tasks should run.

scheduler.Start(60 * time.Second)  // Run tasks for 60 seconds

And that's it! Now, TASKINATOR is at your service, doing all those tasks you've scheduled on the desired interval.


Contribution ✨

Feel free to report issues or create a pull-request. All contributions are welcome.


ACKNOWLEDGEMENT 💖

Thanks goes to those wonderful people who inspired or contributed in any way towards the development of TASKINATOR.


Let TASKINATOR bring success to your task scheduling needs! 🎉

Made with 💙 and Go.

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Scheduler ¶

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

Scheduler represents a task scheduler

func NewScheduler ¶

func NewScheduler() *Scheduler

NewScheduler creates a new task scheduler

func (*Scheduler) AddTask ¶

func (s *Scheduler) AddTask(task Task)

AddTask adds a task to the scheduler

func (*Scheduler) Start ¶

func (s *Scheduler) Start(duration ...time.Duration)

Start starts the task scheduler for the specified duration

type Task ¶

type Task struct {
	Name       string
	Schedule   time.Duration
	MaxRetries int
	RetryDelay time.Duration
	Action     func() error
}

Task represents a scheduled task

Jump to

Keyboard shortcuts

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