Go Task Scheduler (Gts) | GitLocker.com Product

Go Task Scheduler (GTS)

Last updated:

0 purchases

Go Task Scheduler (GTS) Image
Go Task Scheduler (GTS) Images

$6.00

Languages

Go

Categories

Automation Schduling
Add to Cart

Description:

The Go Task Scheduler (GTS) is a lightweight library designed for scheduling and executing goroutines after a specified duration or at a precise time. It also includes a storage mechanism to retain task history and handle task execution during application downtime.

Features:

  1. Flexible Scheduling:
    • Execute tasks after a specific duration.
    • Execute tasks at a defined point in time.
    • Execute recurring tasks at regular intervals.
  2. Task Storage:
    • Persists task history for accountability and recovery.
    • Built-in support for storage options like Sqlite3 and NoOp.
    • Redis storage (coming soon).

Requirements:

System Requirements

  • Go installed on your machine.
  • SQLite3 for persistent storage (if using SqliteStorage).

Library Requirements

  • Install the GTS library:
     

    bash

    Copy code

    go get github.com/rakanalh/scheduler

Instructions:

Installation

  1. Install the Go Task Scheduler library:
     

    bash

    Copy code

    go get github.com/rakanalh/scheduler

  2. (Optional) Ensure SQLite3 is installed for persistent storage.

2. Configuration

Step 1: Choose a Storage Option:

  • NoOpStorage: For temporary, non-persistent task execution.
  • MemoryStorage: Non-persistent in-memory storage for tasks.
  • SqliteStorage: Persistent task storage using SQLite3.

Step 2: Initialize the Storage and Scheduler:
Example using SQLite3:

 

go

Copy code

sqliteStorage := storage.NewSqlite3Storage(storage.Sqlite3Config{DbName: "db.store"}) if err := sqliteStorage.Connect(); err != nil { log.Fatal("Could not connect to the database", err) } if err := sqliteStorage.Initialize(); err != nil { log.Fatal("Could not initialize the database", err) } s := scheduler.New(sqliteStorage)

3. Usage

Schedule Tasks:

  • Execute a task after a specific duration:

     

    go

    Copy code

    func MyFunc(arg1, arg2 string) { fmt.Println(arg1, arg2) } taskID := s.RunAfter(5*time.Second, MyFunc, "Hello", "World")

  • Execute a task at a particular time:

     

    go

    Copy code

    taskID := s.RunAt(time.Now().Add(24*time.Hour), MyFunc, "Hello", "World")

  • Execute recurring tasks:

     

    go

    Copy code

    taskID := s.RunEvery(1*time.Minute, MyFunc, "Hello", "World")

Custom Storage:
Implement the TaskStore interface if a custom storage solution is needed:

 

go

Copy code

type TaskStore interface { Store(task *TaskAttributes) error Remove(task *TaskAttributes) error Fetch() ([]TaskAttributes, error) }

Task Attributes Structure:

 

go

Copy code

type TaskAttributes struct { Hash string Name string LastRun string NextRun string Duration string IsRecurring string Params string }

4. Examples

Check the Examples folder in the repository for sample implementations:

  • Scheduling tasks using different storage types.
  • Handling recurring tasks.
  • Creating and using custom storage.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product: (if this is empty don't purchase this product)

Customer Reviews

There are no reviews.