Browse Source

Fix db null exception while start cron job

pull/70/head
rogerluo410 2 months ago
parent
commit
d7490b4955
5 changed files with 21 additions and 2 deletions
  1. +0
    -1
      main.go
  2. +3
    -0
      models/models.go
  3. +4
    -1
      modules/timer/timer.go
  4. +2
    -0
      options/locale/locale_en-US.ini
  5. +12
    -0
      routers/init.go

+ 0
- 1
main.go View File

@@ -21,7 +21,6 @@ import (
_ "code.gitea.io/gitea/modules/markup/csv"
_ "code.gitea.io/gitea/modules/markup/markdown"
_ "code.gitea.io/gitea/modules/markup/orgmode"
_ "code.gitea.io/gitea/modules/timer"

"github.com/urfave/cli"
)


+ 3
- 0
models/models.go View File

@@ -151,6 +151,9 @@ func getEngine() (*xorm.Engine, error) {
engine.Dialect().SetParams(map[string]string{"rowFormat": "DYNAMIC"})
}
engine.SetSchema(setting.Database.Schema)

HasEngine = true

return engine, nil
}



+ 4
- 1
modules/timer/timer.go View File

@@ -3,10 +3,13 @@ package timer
import (
"github.com/robfig/cron/v3"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/routers/repo"
)

func init() {
func LaunchCronJob() {
log.Trace("Run cron job")

c := cron.New()

spec := "*/10 * * * *"


+ 2
- 0
options/locale/locale_en-US.ini View File

@@ -1956,6 +1956,8 @@ dashboard.cron.finished=Cron: %[1]s has finished
dashboard.delete_inactive_accounts = Delete all unactivated accounts
dashboard.delete_inactive_accounts.started = Delete all unactivated accounts task started.
dashboard.delete_repo_archives = Delete all repository archives
dashboard.start_cron_job = Start to run cron jobs
dashboard.start_cron_job_failed = Start to run cron jobs failed
dashboard.delete_repo_archives.started = Delete all repository archives task started.
dashboard.delete_missing_repos = Delete all repositories missing their Git files
dashboard.delete_missing_repos.started = Delete all repositories missing their Git files task started.


+ 12
- 0
routers/init.go View File

@@ -31,6 +31,7 @@ import (
"code.gitea.io/gitea/modules/ssh"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/task"
"code.gitea.io/gitea/modules/timer"
"code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/mailer"
mirror_service "code.gitea.io/gitea/services/mirror"
@@ -134,6 +135,17 @@ func GlobalInit(ctx context.Context) {

NewServices()

// Launch cron job after DB configured.
if models.HasEngine {
log.Info("%s", unknwoni18n.Tr("en-US", "admin.dashboard.start_cron_job"))
go timer.LaunchCronJob()
} else {
if err := models.SetEngine(); err == nil {
log.Info("%s", unknwoni18n.Tr("en-US", "admin.dashboard.start_cron_job"))
go timer.LaunchCronJob()
}
}

if setting.InstallLock {
highlight.NewContext()
external.RegisterParsers()


Loading…
Cancel
Save