Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Try fix oom #10

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
37 changes: 37 additions & 0 deletions .github/workflow/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release
on:
pull_request:
branches: [ master ]
paths:
- '.github/workflow/release.yaml'

jobs:
release:
runs-on: ubuntu-latest
env:
VERSION: v0.0.2
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.21'

- name: Build
run: go build -v ./...

- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${{ env.VERSION }}

- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: Release ${{ steps.get_version.outputs.VERSION }}
draft: false
prerelease: false
10 changes: 2 additions & 8 deletions cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package cron

import (
"github.com/sirupsen/logrus"
"sort"
"time"
)
Expand Down Expand Up @@ -110,7 +109,7 @@ func (c *Cron) IsTight() bool {
return c.tight
}

// A wrapper that turns a func() into a cron.Job
// FuncJob A wrapper that turns a func() into a cron.Job
type FuncJob func()

func (f FuncJob) Run() { f() }
Expand Down Expand Up @@ -232,10 +231,7 @@ func (c *Cron) run() {
e := runEarlyEntry.CurrentEntry
e.Prev = runEarlyEntry.EndTime
e.Next = e.Schedule.Next(runEarlyEntry.EndTime)
logrus.WithField("name", runEarlyEntry.CurrentEntry.Name).WithField("prev", runEarlyEntry.CurrentEntry.Prev).WithField("next", runEarlyEntry.CurrentEntry.Next).Infof("Start Run early entry")
go c.execute(e)
logrus.WithField("name", runEarlyEntry.CurrentEntry.Name).WithField("prev", runEarlyEntry.CurrentEntry.Prev).WithField("next", runEarlyEntry.CurrentEntry.Next).Infof("End Run early entry")

}
continue
case now = <-time.After(effective.Sub(now)):
Expand All @@ -246,9 +242,7 @@ func (c *Cron) run() {
}
e.Prev = e.Next
e.Next = e.Schedule.Next(effective)
logrus.WithField("name", e.Name).WithField("prev", e.Prev).WithField("next", e.Next).Infof("Start Run entry")
go c.execute(e)
logrus.WithField("name", e.Name).WithField("prev", e.Prev).WithField("next", e.Next).Infof("End Run entry")
}
continue

Expand All @@ -275,7 +269,7 @@ func (c *Cron) run() {
case <-c.stop:
return
default:
// avoid bloc
// avoid block
}

// 'now' should be updated after newEntry and snapshot cases.
Expand Down
35 changes: 16 additions & 19 deletions cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ func TestSnapshotEntries(t *testing.T) {
defer cron.Stop()

// Cron should fire in 2 seconds. After 1 second, call Entries.
select {
case <-time.After(ONE_SECOND):
cron.Entries()
}
time.Sleep(ONE_SECOND)

// Even though Entries was called, the cron should fire at the 2 second mark.
select {
Expand Down Expand Up @@ -187,7 +184,7 @@ func TestRunEverMsWithOneMs(t *testing.T) {
occupied.Store(false)
}()
time.Sleep(100 * time.Millisecond)
t.Logf("exec %v", time.Now().Sub(start))
t.Logf("exec %v", time.Since(start))
wg.Done()
}), "test20")
cron.Start()
Expand All @@ -197,9 +194,9 @@ func TestRunEverMsWithOneMs(t *testing.T) {
case <-time.After(2 * ONE_SECOND):
t.FailNow()
case <-wait(wg):
t.Log(time.Now().Sub(s))
if time.Now().Sub(s) < 1500*time.Millisecond {
t.Errorf("time %v", time.Now().Sub(s))
t.Log(time.Since(s))
if time.Since(s) < 1500*time.Millisecond {
t.Errorf("time %v", time.Since(s))
}
}
}
Expand Down Expand Up @@ -229,7 +226,7 @@ func TestRunEveryMs(t *testing.T) {
occupied.Store(false)
}()
time.Sleep(600 * time.Millisecond)
t.Logf("exec %v", time.Now().Sub(start))
t.Logf("exec %v", time.Since(start))
wg.Done()
}), "test19")
cron.Start()
Expand All @@ -239,9 +236,9 @@ func TestRunEveryMs(t *testing.T) {
case <-time.After(3 * ONE_SECOND):
t.FailNow()
case <-wait(wg):
t.Log(time.Now().Sub(s))
if time.Now().Sub(s) < 1800*time.Millisecond {
t.Errorf("time %v", time.Now().Sub(s))
t.Log(time.Since(s))
if time.Since(s) < 1800*time.Millisecond {
t.Errorf("time %v", time.Since(s))
}
}
}
Expand Down Expand Up @@ -273,7 +270,7 @@ func TestRunTight(t *testing.T) {
occupied.Store(false)
}()
time.Sleep(1100 * time.Millisecond)
t.Logf("exec %v", time.Now().Sub(start))
t.Logf("exec %v", time.Since(start))
wg.Done()
}), "test18")
cron.Start()
Expand All @@ -282,9 +279,9 @@ func TestRunTight(t *testing.T) {
case <-time.After(6 * ONE_SECOND):
t.FailNow()
case <-wait(wg):
t.Log(time.Now().Sub(s))
if time.Now().Sub(s) < 4400*time.Millisecond {
t.Errorf("time %v", time.Now().Sub(s))
t.Log(time.Since(s))
if time.Since(s) < 4400*time.Millisecond {
t.Errorf("time %v", time.Since(s))
}
}
}
Expand Down Expand Up @@ -318,7 +315,7 @@ func TestRunNoTight(t *testing.T) {
occupied.Store(false)
}()
time.Sleep(1100 * time.Millisecond)
t.Logf("exec %v", time.Now().Sub(start))
t.Logf("exec %v", time.Since(start))
wg.Done()
}), "test18")
cron.Start()
Expand All @@ -327,8 +324,8 @@ func TestRunNoTight(t *testing.T) {
case <-time.After(9 * ONE_SECOND):
t.FailNow()
case <-wait(wg):
if time.Now().Sub(s) < 7*time.Second {
t.Errorf("time %v", time.Now().Sub(s))
if time.Since(s) < 7*time.Second {
t.Errorf("time %v", time.Since(s))
}
if skipTimes != 4 {
t.Errorf("skipTimes %v", skipTimes)
Expand Down
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module github.com/databendcloud/cron

go 1.21.1

require github.com/sirupsen/logrus v1.9.3

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
15 changes: 0 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +0,0 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *SpecSchedule) Next(t time.Time) time.Time {
// values)

// Start at the earliest possible time (the upcoming second).
var localTz *time.Location = t.Location()
var localTz = t.Location()
// use the schedule's timezone if it's set
// return to the local timezone when done
if s.TimeZone != nil {
Expand Down