package main

import (
	"fmt"
	"github.com/robfig/cron/v3"
	"time"
	"video_data_copy/db"
)

func main() {
	_testDbConn()
	//_startCopyData()
	c := cron.New()
	_, err := c.AddFunc("0 4 * * *", func() {
		fmt.Println("定时任务开始执行")
		_startCopyData()
	})
	if err != nil {
		fmt.Printf("添加定时任务出错: %v\n", err)
		return
	}

	fmt.Println("定时任务启动成功")
	c.Start()

	select {}
}

func _testDbConn() {
	db.ConnectDB()
	time.Sleep(10 * time.Second)
	db.DisconnectDB()
}

func _startCopyData() {
	db.ConnectDB()
	db.CopyData()
	time.Sleep(10 * time.Second)
	db.DisconnectDB()
}
