Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dipeshdulal/event-scheduling
Golang Event Scheduling Sample Using Postgresql Database as persisting layer.
https://github.com/dipeshdulal/event-scheduling
event-scheduler go postgresql
Last synced: 23 days ago
JSON representation
Golang Event Scheduling Sample Using Postgresql Database as persisting layer.
- Host: GitHub
- URL: https://github.com/dipeshdulal/event-scheduling
- Owner: dipeshdulal
- Created: 2021-01-16T04:08:38.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-25T03:42:53.000Z (almost 4 years ago)
- Last Synced: 2024-10-02T09:11:39.547Z (about 1 month ago)
- Topics: event-scheduler, go, postgresql
- Language: Go
- Homepage:
- Size: 31.3 KB
- Stars: 53
- Watchers: 5
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### 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
```go
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.
```go
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...
```