cron

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cron contains cron jobs and other logging functions

Index

Examples

Constants

This section is empty.

Variables

View Source
var CronJobs cronJobs

CronJobs provides a cron job engine for golang function callbacks to schedule events to execute at specific times of the day and week.

Functions

func ExecuteOneTimeJob

func ExecuteOneTimeJob(jobName string, callback OneTimeEvent)

ExecuteOneTimeJob executes a one time job.

Example

ExampleExecuteOneTimeJob is an example of how to execute a one time event.

package main

import (
	"github.com/DanielRenne/GoCore/core/cron"
	"github.com/DanielRenne/GoCore/core/fileCache"
	"github.com/DanielRenne/GoCore/core/zip"
)

func main() {
	// You can set the CACHE_STORAGE_PATH export to a folder on your system to use the goCore fileCache.
	// fileCache.CACHE_STORAGE_PATH = "/my/goCore/cachePath"
	fileCache.Initialize()
	cron.Start()
	cb := func() bool {
		err := zip.Unzip("test", "test", []string{})
		if err != nil {
			return false
		}
		return true
	}
	cron.CronJobs.ExecuteOneTimeJob("run me and i will save a key of this string and write the boolean of success or not to /usr/local/goCore/jobs/jobs.json for historical purposes", cb)
}

func Start

func Start()

Start starts the cron job engine which tickers every 100 ms. Include this in your main somewhere

Example

ExampleStart is an example of how to start the cron job engine (note you must initialize fileCache first if you are not using app.Initialize() or app.InitializeLite() to run a webserver (which do this automatically for you)

package main

import (
	"github.com/DanielRenne/GoCore/core/cron"
	"github.com/DanielRenne/GoCore/core/fileCache"
)

func main() {
	// You can set the CACHE_STORAGE_PATH export to a folder on your system to use the goCore fileCache.
	// fileCache.CACHE_STORAGE_PATH = "/my/goCore/cachePath"
	fileCache.Initialize()
	cron.Start()
}

Types

type CronJob

type CronJob struct {
}

CronJob entity provides details of the cron job to be executed.

type OnDemandEvent

type OnDemandEvent func(id string, eventTime time.Time, context interface{})

OnDemandEvent is used as the callback function for the event.

type OneTimeEvent

type OneTimeEvent func() bool

OneTimeEvent is used to schedule a one time event to be executed

type RecurringEvent

type RecurringEvent func(eventDate time.Time)

RecurringEvent is a callback function called by the cron job engine.

type RecurringType

type RecurringType int

RecurringType defines a type of cron job.

const (
	//CRON_TOP_OF_MINUTE is a cron job type that is called at the top of every minute.
	CRON_TOP_OF_MINUTE RecurringType = iota
	//CRON_TOP_OF_HOUR is a cron job type that is called at the top of every hour.
	CRON_TOP_OF_HOUR
	//CRON_TOP_OF_DAY is a cron job type that is called at the top of every day.
	CRON_TOP_OF_DAY
	//CRON_TOP_OF_30_SECONDS is a cron job type that is called at the top of every 30 seconds.
	CRON_TOP_OF_30_SECONDS
	//CRON_TOP_OF_SECOND is a cron job type that is called at the top of every second.
	CRON_TOP_OF_SECOND
)

Jump to

Keyboard shortcuts

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