Golang Event Scheduling Sample Using Postgresql Database as persisting layer.

Database Based Event Scheduling

Example that demonstrates super basic database based event scheduling.

To run this example;

  • Copy .env.example to .env and update postgres database dsn.
  • Run go run .

Basically,

  • When we want to schedule a job, we add to database
scheduler.Schedule("SendEmail", "mail: [email protected]", time.Now().Add(1*time.Minute)) 
  • Another go routine is always looking for jobs to execute (that has time expired) in the given interval.
scheduler.CheckEventsInInterval(ctx, time.Minute)

Output looks like;

2021/01/16 11:58:49 💾 Seeding database with table...
2021/01/16 11:58:49 🚀 Scheduling event SendEmail to run at 2021-01-16 11:59:49.344904505 +0545 +0545 m=+60.004623549
2021/01/16 11:58:49 🚀 Scheduling event PayBills to run at 2021-01-16 12:00:49.34773798 +0545 +0545 m=+120.007457039
2021/01/16 11:59:49 ⏰ Ticks Received...
2021/01/16 11:59:49 📨 Sending email with data:  mail: [email protected]
2021/01/16 12:00:49 ⏰ Ticks Received...
2021/01/16 12:01:49 ⏰ Ticks Received...
2021/01/16 12:01:49 💲 Pay me a bill:  paybills: $4,000 bill
2021/01/16 12:02:49 ⏰ Ticks Received...
2021/01/16 12:03:49 ⏰ Ticks Received...
^C2021/01/16 12:03:57 
❌ Interrupt received closing...
Owner
Dipesh Dulal
{{ React, PHP, Angular, GO, Express }}
Dipesh Dulal
Similar Resources

Database agnostic ORM for Go

If you are looking for something more lightweight and flexible, have a look at jet For questions, suggestions and general topics visit the group. Inde

Nov 28, 2022

Generate a Go ORM tailored to your database schema.

Generate a Go ORM tailored to your database schema.

SQLBoiler is a tool to generate a Go ORM tailored to your database schema. It is a "database-first" ORM as opposed to "code-first" (like gorm/gorp). T

Jan 2, 2023

Converts a database into gorm structs and RESTful api

gen The gen tool produces a CRUD (Create, read, update and delete) REST api project template from a given database. The gen tool will connect to the d

Dec 28, 2022

Simple REST API application using GO [/net/http & mux]

REST-API-CRUD Simple REST API application using GOLANG [/net/http & mux] Available URLs: URL METHOD http://127.0.0.1:8888/ GET http://127.0.0.1:8888/l

Dec 3, 2021

CURD using go fiber - gorm - mysql

GO Fiber - CRUD - GORM - Mysql Folder Structure - database | database config |- migration | migration config - middleware | mid

Nov 13, 2022

A example of a join table using liquibase and gorm

A example of a join table using liquibase and gorm. Additionally the join table's composite key is used as a composite foreign key for another table.

Feb 4, 2022

Simple-crm-system - Simple CRM system CRUD backend using Go, Fiber, SQLite, Gorm

Simple CRM system CRUD backend using GO, Fiber, Gorm, SQLite Developent go mod t

Nov 13, 2022

Mikorm - Library ORM Mikrotik API using go

Mikorm - Library ORM Mikrotik API using go

Mikrotik ORM (mikorm) Library Mikrotik API menggunakan ORM untuk mempermudah int

Jun 28, 2022

RestAPI Starter Template Using Go (Gin + Gorm)

go-gin-gorm-restapi-template Go (Gin + Gorm) を使用した RestAPI 開発のスターターテンプレート RestAPI Starter Template Using Golang (Gin + Gorm) 主要な依存ライブラリ Gin (Web フレームワ

Apr 3, 2022
Comments
  • Add cron jobs scheduling support

    Add cron jobs scheduling support

    What this pull request contains:

    Adding Sample for Cron Job Implementation.

    • Add cron job library.
    • Update database table to include cron entry as well.
    • Added ScheduleCron and StartCron methods to schedule the cron and start the cron job. If there is already the same name present in the database for cron job the entry is updated. If not new entry is added to the database.

    Initially to start cron job

    stopCron := scheduler.StartCron()
    defer stopCron()
    

    To Schedule

    scheduler.ScheduleCron("SendEmail", "mail: [email protected]", "* * * * *")
    
Simple project in Go to play around with some CRUD operations using a PostgreSQL database and pgx

Record Store November 2021 I started learning Go a few weeks ago and this is my first proper project using Go. I wanted to use it to get to grips with

Nov 26, 2021
Using-orm-with-db - Trying to use ORM to work with PostgreSQL
Using-orm-with-db - Trying to use ORM to work with PostgreSQL

Using ORM with db This repo contains the training (rough) code, and possibly not

Jul 31, 2022
A pure golang SQL database for learning database theory

Go SQL DB 中文 "Go SQL DB" is a relational database that supports SQL queries for research purposes. The main goal is to show the basic principles and k

Dec 29, 2022
100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood.

go-queryset 100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood. Contents

Dec 30, 2022
Golang ORM with focus on PostgreSQL features and performance

go-pg is in a maintenance mode and only critical issues are addressed. New development happens in Bun repo which offers similar functionality but works with PostgreSQL, MySQL, and SQLite.

Jan 8, 2023
Api-project - Api project with Golang, Gorm, Gorilla-Mux, Postgresql

TECHNOLOGIES GOLANG 1.14 GORM GORILLA-MUX POSTGRESQL API's PATHS For Product Ser

Nov 23, 2022
Examples of using various popular database libraries and ORM in Go.

Introduction Examples of using various popular database libraries and ORM in Go. sqlx sqlc Gorm sqlboiler ent The aim is to demonstrate and compare us

Dec 12, 2021
Examples of using various popular database libraries and ORM in Go.

Introduction Examples of using various popular database libraries and ORM in Go. sqlx sqlc Gorm sqlboiler ent The aim is to demonstrate and compare us

Dec 28, 2022
Golang struct-to-table database mapper

Structable: Struct-Table Mapping for Go Warning: This is the Structable 4 development branch. For a stable release, use version 3.1.0. Structable deve

Dec 27, 2022
beedb is a go ORM,support database/sql interface,pq/mysql/sqlite

Beedb ❗ IMPORTANT: Beedb is being deprecated in favor of Beego.orm ❗ Beedb is an ORM for Go. It lets you map Go structs to tables in a database. It's

Nov 25, 2022