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", Use: "dump",
Short: "Dump all vikunja data into a zip file. Includes config, files and db.", Short: "Dump all vikunja data into a zip file. Includes config, files and db.",
PreRun: func(cmd *cobra.Command, args []string) { PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInit() initialize.FullInitWithoutAsync()
}, },
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
filename := "vikunja-dump_" + time.Now().Format("2006-01-02_15-03-05") + ".zip" 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", Use: "index",
Short: "Reindex all of Vikunja's data into Typesense. This will remove any existing index.", Short: "Reindex all of Vikunja's data into Typesense. This will remove any existing index.",
PreRun: func(cmd *cobra.Command, args []string) { PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInit() initialize.FullInitWithoutAsync()
}, },
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if !config.TypesenseEnabled.GetBool() { if !config.TypesenseEnabled.GetBool() {

View File

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

View File

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