Skip to content

Commit

Permalink
Hotfix for log pagination, apparently the cron library needs separate…
Browse files Browse the repository at this point in the history
… instances to run, and memory management was messing up my solves. Fixes #5
  • Loading branch information
AtomicNicos committed Sep 22, 2022
1 parent 4e31c9d commit f6552e5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
24 changes: 22 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Released]

## `0.1.4` - 2022-09-17
## `0.1.5-hotfix` - 2022-09-22
### Fixes
- Issue #5: [Link to issue](https://github.com/digital-overdose/digital-overdose-bot/issues/5s)
### Changed
- How the `cron` scheduler is provisioned, as the current version would mix up memory addresses. TL;DR: Can't run multiple tasks in one scheduler. And one needs to dereference the provided job.

## [0.1.5] - 2022-09-21
### Fixes
- Issue #3: [Link to issue](https://github.com/digital-overdose/digital-overdose-bot/issues/3)
- Issue #4: [Link to issue](https://github.com/digital-overdose/digital-overdose-bot/issues/4)

### Added
- Self-upgrade capability for the bot, via a command. (reliant on systemd restart feature).
- Log pagination at midnight every day.

### Changed
- Target for verification purge channel

## [0.1.4] - 2022-09-17
### Fixes
- Issue #2: [Link to issue](https://github.com/digital-overdose/digital-overdose-bot/issues/2)

Expand Down Expand Up @@ -84,7 +102,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial run code.

[Unreleased]: https://github.com/digital-overdose/digital-overdose-bot/compare/v0.1.3...HEAD
[Unreleased]: https://github.com/digital-overdose/digital-overdose-bot/compare/v0.1.5...HEAD
[0.1.5]: https://github.com/digital-overdose/digital-overdose-bot/compare/v0.1.4...v0.1.5
[0.1.4]: https://github.com/digital-overdose/digital-overdose-bot/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/digital-overdose/digital-overdose-bot/compare/v0.1.2...v0.1.3
[0.1.2]: https://github.com/digital-overdose/digital-overdose-bot/compare/v0.1.1...v0.1.2
[0.1.1]: https://github.com/digital-overdose/digital-overdose-bot/compare/v0.1.0...v0.1.1
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ UPGRADE=https://github.com/digital-overdose/digital-overdose-bot/releases/downlo
## TODO

### Features (Future)
- [ ] `/stats` -> Number of people interacting over 2 weeks. Channel usage. Keep message ID in a file? (Cron)
- [ ] `/stats` Number of people interacting over 2 weeks. Channel usage. Keep message ID in a file? (Cron)

### Features (Important->Critical)
### Features (ImportantCritical)

- [x] Ability to download new binary
- [ ] Ability to restart on a specific binary
- [ ] Ability to list running instances of bot
- [x] Ability to restart on a specific binary
- [x] Ability to list running instances of bot
- [x] Ability to stop a specific instance from reacting to commands (for testing)

### Done
Expand Down
23 changes: 12 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/go-co-op/gocron"
)

var VERSION = "0.1.5"
var VERSION = "0.1.5-hotfix"

// The Discord session, used for state management.
var s *discordgo.Session
Expand Down Expand Up @@ -92,22 +92,23 @@ func init() {

// Initializes cron engine, and subsequently registers scheduled functions
func init() {
cronScheduler = gocron.NewScheduler(time.UTC)

// Register each job individually.
log.Print("[+] Registering Jobs")
for _, j := range cron.CronJobs {
log.Printf("[--] Registered job '%v'", j.Name)
cronScheduler.Cron(j.CronString).Do(func() {
log.Printf("[+] Executing cron job '%v'", j.Name)
j.Job(s, nil)
schedulers := make([]*gocron.Scheduler, len(cron.CronJobs))

for i := 0; i < len(cron.CronJobs); i++ {
schedulers[i] = gocron.NewScheduler(time.UTC)
job := cron.CronJobs[i]

log.Printf("[--] Registered job '%v': '%v'", job.Name, job.CronString)
schedulers[i].Cron(job.CronString).Do(func() {
log.Printf("[+] Executing cron job '%v':'%v", job.Name, &job.Name)
job.Job(s, nil)
})
schedulers[i].StartAsync()
}

log.Print("[✓] Registering Jobs")

// Start the cron scheduler in another thread.
cronScheduler.StartAsync()
log.Print("[✓] cron handler Started")
}

Expand Down

0 comments on commit f6552e5

Please sign in to comment.