isked

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2020 License: MIT Imports: 8 Imported by: 0

README

isked The isked package is the simplified and easy to use task schedulers for your Go projects.

Installation

go get -u github.com/itrepablik/isked

Usage

These are some of the examples on how you can use isked package.

package main

import (
	"fmt"

	"github.com/itrepablik/isked"
)

func myFunc1() {
	fmt.Println("calling from myFunc1(): ")
}

func myFunc2(s string) func() {
	return func() {
		fmt.Println("calling from myFunc4(): ", s)
	}
}

func main() {
	// Frequently methods:
	isked.TaskName("Task 1").Frequently().Seconds(7).ExecFunc(myFunc2("hello world")).AddTask()
	isked.TaskName("Task 2").Frequently().Minutes(1).ExecFunc(myFunc1).AddTask()
	isked.TaskName("Task 3").Frequently().Hours(2).ExecFunc(myFunc1).AddTask()

	// Daily methods:
	// The start date is tomorrow's date, not, today's date
	isked.TaskName("Task 4").Daily().At("14:18").ExecFunc(myFunc1).AddTask()

	// Weekly methods:
	isked.TaskName("Task 6").Weekly().Tuesday().At("17:30").ExecFunc(myFunc1).AddTask()

	// Monthly methods: 0 - means 'last day' of each month
	isked.TaskName("Task 7").Monthly().Every(0).At("09:30").ExecFunc(myFunc1).AddTask()
	isked.TaskName("Task 8").Monthly().Every(2).At("10:30").ExecFunc(myFunc1).AddTask()

	isked.Run()
}

Subscribe to Maharlikans Code Youtube Channel:

Please consider subscribing to my Youtube Channel to recognize my work on this package. Thank you for your support! https://www.youtube.com/channel/UCdAVUmldU9Jn2VntuQChHqQ/

License

Code is distributed under MIT license, feel free to use it in your proprietary projects as well.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChannelTS = make(chan bool, 1)

ChannelTS is the channel to be used during cancellation of all the tasks that are currently running, this is useful when reloading some config variables to get the latest values and reload the task scheduler.

View Source
var DTFormat string = _dateTimeFormat

DTFormat is the standard DateTime format to be used for logging information

View Source
var TK = Tasks{}

TK initialize the 'Tasks' struct with an empty values

View Source
var TS = TaskScheduler{TaskList: make(map[string][]Tasks)}

TS initialize the 'TaskScheduler' struct with an empty values

Functions

func Run added in v1.0.2

func Run()

Run executes the task scheduler's individual task item

Types

type FuncToExec

type FuncToExec func()

FuncToExec is the function that needs to be executed as parameter

type LogDTFormat

type LogDTFormat struct {
	DTFormat string
	// contains filtered or unexported fields
}

LogDTFormat is the DateTime format for each logs

func SetLogDT

func SetLogDT(dtFormat string) *LogDTFormat

SetLogDT customizes the DateTime logging format to be used for each logs

type TaskScheduler

type TaskScheduler struct {
	TaskList map[string][]Tasks
	// contains filtered or unexported fields
}

TaskScheduler is the task scheduler's format

func (*TaskScheduler) Get

func (t *TaskScheduler) Get(taskName string) ([]Tasks, bool)

Get gets the specific task information using the task name

func (*TaskScheduler) Reset

func (t *TaskScheduler) Reset()

Reset clear all scheduled tasks

func (*TaskScheduler) UpdateNextRunTime

func (t *TaskScheduler) UpdateNextRunTime(s *Tasks)

UpdateNextRunTime modify the next run time

type Tasks

type Tasks struct {
	Name              string
	RunType           string     // options: onetime, frequently, daily, weekly, monthly
	FrequencyInterval string     // use for frequently option only: seconds, minutes, hours
	FrequencyValue    int        // use for frequently option only, minimum value of 1, e.g 1 second
	ExecuteFunc       FuncToExec // user's defined func to be executed
	// contains filtered or unexported fields
}

Tasks is the individual task item to be executed

func TaskName added in v1.0.2

func TaskName(taskName string) *Tasks

TaskName method is the run type option of each task that execute once only

func (*Tasks) AddTask

func (s *Tasks) AddTask()

AddTask create individual task to be executed

func (*Tasks) At

func (s *Tasks) At(rt string) *Tasks

At method is when to start executing the task with DateTime in unix time format

func (*Tasks) Daily

func (s *Tasks) Daily() *Tasks

Daily method is the run type option of each task that execute every day

func (*Tasks) Every

func (s *Tasks) Every(day int) *Tasks

Every is use mainly for the 'Monthly' method that serve as the specific day of each month

func (*Tasks) ExecFunc

func (s *Tasks) ExecFunc(fn FuncToExec) *Tasks

ExecFunc method collect the function as parameter that needs to be executed

func (*Tasks) Frequently

func (s *Tasks) Frequently() *Tasks

Frequently method is the run type option of each task that execute frequently Options: seconds, minutes, hours

func (*Tasks) Friday

func (s *Tasks) Friday() *Tasks

Friday is the naming convention for the day called 'Friday' method

func (*Tasks) Hours

func (s *Tasks) Hours(interval int) *Tasks

Hours is the naming convention for the Frequently method as 'hours' option

func (*Tasks) Minutes

func (s *Tasks) Minutes(interval int) *Tasks

Minutes is the naming convention for the Frequently method as 'minutes' option

func (*Tasks) Monday

func (s *Tasks) Monday() *Tasks

Monday is the naming convention for the day called 'Monday' method

func (*Tasks) Monthly

func (s *Tasks) Monthly() *Tasks

Monthly method is the run type option of each task that execute every month

func (*Tasks) OneTime

func (s *Tasks) OneTime(dt int64) *Tasks

OneTime method requires unix DateTime format that executes only once

func (*Tasks) Saturday

func (s *Tasks) Saturday() *Tasks

Saturday is the naming convention for the day called 'Saturday' method

func (*Tasks) Seconds

func (s *Tasks) Seconds(interval int) *Tasks

Seconds is the naming convention for the Frequently method as 'seconds' option

func (*Tasks) Sunday

func (s *Tasks) Sunday() *Tasks

Sunday is the naming convention for the day called 'Sunday' method

func (*Tasks) Thursday

func (s *Tasks) Thursday() *Tasks

Thursday is the naming convention for the day called 'Thursday' method

func (*Tasks) Tuesday

func (s *Tasks) Tuesday() *Tasks

Tuesday is the naming convention for the day called 'Tuesday' method

func (*Tasks) Wednesday

func (s *Tasks) Wednesday() *Tasks

Wednesday is the naming convention for the day called 'Wednesday' method

func (*Tasks) Weekly

func (s *Tasks) Weekly() *Tasks

Weekly method is the run type option of each task that execute every week

Jump to

Keyboard shortcuts

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