[#4394] reschedule the first cron tick to start at 00 second
This commit is contained in:
parent
f2ed186540
commit
5a715cc60a
|
@ -22,6 +22,9 @@
|
||||||
oauth2
|
oauth2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- Updated the `cron.Start()` to start the ticker at the `00` second of the cron interval ([#4394](https://github.com/pocketbase/pocketbase/discussions/4394)).
|
||||||
|
_Note that the cron format has only minute granularity and there is still no guarantee that the sheduled job will be always executed at the `00` second._
|
||||||
|
|
||||||
- Upgraded to `aws-sdk-go-v2` and added special handling for GCS to workaround the previous [GCS headers signature issue](https://github.com/pocketbase/pocketbase/issues/2231) that we had with v2.
|
- Upgraded to `aws-sdk-go-v2` and added special handling for GCS to workaround the previous [GCS headers signature issue](https://github.com/pocketbase/pocketbase/issues/2231) that we had with v2.
|
||||||
_This should also fix the SVG/JSON zero response when using Cloudflare R2 ([#4287](https://github.com/pocketbase/pocketbase/issues/4287#issuecomment-1925168142), [#2068](https://github.com/pocketbase/pocketbase/discussions/2068), [#2952](https://github.com/pocketbase/pocketbase/discussions/2952))._
|
_This should also fix the SVG/JSON zero response when using Cloudflare R2 ([#4287](https://github.com/pocketbase/pocketbase/issues/4287#issuecomment-1925168142), [#2068](https://github.com/pocketbase/pocketbase/discussions/2068), [#2952](https://github.com/pocketbase/pocketbase/discussions/2952))._
|
||||||
_If you are using S3 for uploaded files or backups, please verify that you have a green check in the Admin UI for your S3 configuration (I've tested the new version with GCS, MinIO, Cloudflare R2 and Wasabi)._
|
_If you are using S3 for uploaded files or backups, please verify that you have a green check in the Admin UI for your S3 configuration (I've tested the new version with GCS, MinIO, Cloudflare R2 and Wasabi)._
|
||||||
|
|
|
@ -22,12 +22,13 @@ type job struct {
|
||||||
|
|
||||||
// Cron is a crontab-like struct for tasks/jobs scheduling.
|
// Cron is a crontab-like struct for tasks/jobs scheduling.
|
||||||
type Cron struct {
|
type Cron struct {
|
||||||
sync.RWMutex
|
timezone *time.Location
|
||||||
|
ticker *time.Ticker
|
||||||
|
startTimer *time.Timer
|
||||||
|
jobs map[string]*job
|
||||||
|
interval time.Duration
|
||||||
|
|
||||||
interval time.Duration
|
sync.RWMutex
|
||||||
timezone *time.Location
|
|
||||||
ticker *time.Ticker
|
|
||||||
jobs map[string]*job
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New create a new Cron struct with default tick interval of 1 minute
|
// New create a new Cron struct with default tick interval of 1 minute
|
||||||
|
@ -132,6 +133,11 @@ func (c *Cron) Stop() {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
|
if c.startTimer != nil {
|
||||||
|
c.startTimer.Stop()
|
||||||
|
c.startTimer = nil
|
||||||
|
}
|
||||||
|
|
||||||
if c.ticker == nil {
|
if c.ticker == nil {
|
||||||
return // already stopped
|
return // already stopped
|
||||||
}
|
}
|
||||||
|
@ -146,15 +152,26 @@ func (c *Cron) Stop() {
|
||||||
func (c *Cron) Start() {
|
func (c *Cron) Start() {
|
||||||
c.Stop()
|
c.Stop()
|
||||||
|
|
||||||
c.Lock()
|
// delay the ticker to start at 00 of 1 c.interval duration
|
||||||
c.ticker = time.NewTicker(c.interval)
|
now := time.Now()
|
||||||
c.Unlock()
|
next := now.Add(c.interval).Truncate(c.interval)
|
||||||
|
delay := next.Sub(now)
|
||||||
|
|
||||||
go func() {
|
c.startTimer = time.AfterFunc(delay, func() {
|
||||||
for t := range c.ticker.C {
|
c.Lock()
|
||||||
c.runDue(t)
|
c.ticker = time.NewTicker(c.interval)
|
||||||
}
|
c.Unlock()
|
||||||
}()
|
|
||||||
|
// run immediately at 00
|
||||||
|
c.runDue(time.Now())
|
||||||
|
|
||||||
|
// run after each tick
|
||||||
|
go func() {
|
||||||
|
for t := range c.ticker.C {
|
||||||
|
c.runDue(t)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasStarted checks whether the current Cron ticker has been started.
|
// HasStarted checks whether the current Cron ticker has been started.
|
||||||
|
|
Loading…
Reference in New Issue