diff --git a/.github/workflow/release.yaml b/.github/workflow/release.yaml new file mode 100644 index 0000000..b80e4b3 --- /dev/null +++ b/.github/workflow/release.yaml @@ -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 \ No newline at end of file diff --git a/cron.go b/cron.go index 141e53a..e5986d9 100644 --- a/cron.go +++ b/cron.go @@ -3,7 +3,6 @@ package cron import ( - "github.com/sirupsen/logrus" "sort" "time" ) @@ -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() } @@ -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)): @@ -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 @@ -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. diff --git a/cron_test.go b/cron_test.go index cdf964b..871792d 100644 --- a/cron_test.go +++ b/cron_test.go @@ -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 { @@ -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() @@ -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)) } } } @@ -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() @@ -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)) } } } @@ -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() @@ -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)) } } } @@ -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() @@ -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) diff --git a/go.mod b/go.mod index ebca1e6..4a9bce7 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 21f9bfb..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/spec.go b/spec.go index 3bc7e8f..ea0aaf4 100644 --- a/spec.go +++ b/spec.go @@ -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 {