fix(cmd): do not initialize asnyc operations when running certain cli commands

This commit is contained in:
kolaente 2023-09-04 11:22:50 +02:00
parent f38535b2f4
commit c28d1af877
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 13 additions and 8 deletions

View File

@ -33,7 +33,7 @@ var dumpCmd = &cobra.Command{
Use: "dump",
Short: "Dump all vikunja data into a zip file. Includes config, files and db.",
PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInit()
initialize.FullInitWithoutAsync()
},
Run: func(cmd *cobra.Command, args []string) {
filename := "vikunja-dump_" + time.Now().Format("2006-01-02_15-03-05") + ".zip"

View File

@ -32,7 +32,7 @@ var indexCmd = &cobra.Command{
Use: "index",
Short: "Reindex all of Vikunja's data into Typesense. This will remove any existing index.",
PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInit()
initialize.FullInitWithoutAsync()
},
Run: func(cmd *cobra.Command, args []string) {
if !config.TypesenseEnabled.GetBool() {

View File

@ -32,7 +32,7 @@ var restoreCmd = &cobra.Command{
Short: "Restores all vikunja data from a vikunja dump.",
Args: cobra.ExactArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInit()
initialize.FullInitWithoutAsync()
},
Run: func(cmd *cobra.Command, args []string) {
if err := dump.Restore(args[0]); err != nil {

View File

@ -17,6 +17,8 @@
package initialize
import (
"code.vikunja.io/api/pkg/mail"
"code.vikunja.io/api/pkg/migration"
"time"
"code.vikunja.io/api/pkg/config"
@ -24,8 +26,6 @@ import (
"code.vikunja.io/api/pkg/events"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/mail"
"code.vikunja.io/api/pkg/migration"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/auth/openid"
"code.vikunja.io/api/pkg/modules/keyvalue"
@ -60,9 +60,8 @@ func InitEngines() {
}
}
// FullInit initializes all kinds of things in the right order
func FullInit() {
// FullInitWithoutAsync does a full init without any async handlers (cron or events)
func FullInitWithoutAsync() {
LightInit()
// Initialize the files handler
@ -79,6 +78,12 @@ func FullInit() {
// Start the mail daemon
mail.StartMailDaemon()
}
// FullInit initializes all kinds of things in the right order
func FullInit() {
FullInitWithoutAsync()
// Start the cron
cron.Init()