mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
clean the cron job
This commit is contained in:
parent
c9380481cf
commit
d07dc199b7
2 changed files with 26 additions and 40 deletions
|
|
@ -16,7 +16,7 @@ func main() {
|
|||
Name: "Monthly Booking Report",
|
||||
Schedule: "minute",
|
||||
//Schedule: "monthly",
|
||||
Action: cron.JobMonthlyBookingReport,
|
||||
// Action: cron.JobMonthlyBookingReport,
|
||||
})
|
||||
|
||||
go scheduler.Start()
|
||||
|
|
|
|||
|
|
@ -1,46 +1,32 @@
|
|||
package cron
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
// func JobMonthlyBookingReport() error {
|
||||
// _ = godotenv.Load()
|
||||
// db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL")), &gorm.Config{})
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("error connecting to the database %w", err)
|
||||
// }
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
// now := time.Now()
|
||||
// log.Println("Start Monthly Booking Report job at:", now)
|
||||
|
||||
"github.com/rjNemo/rentease/internal/driver/pdf"
|
||||
"github.com/rjNemo/rentease/internal/service/booking"
|
||||
)
|
||||
// ps, err := pdf.NewPdfClient(
|
||||
// os.Getenv("HTMLDOCS_PROJECT_ID"),
|
||||
// os.Getenv("HTMLDOCS_REPORT_PROJECT_ID"),
|
||||
// os.Getenv("HTMLDOCS_URL"),
|
||||
// os.Getenv("HTMLDOCS_KEY"),
|
||||
// )
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("error starting pdf service %w", err)
|
||||
// }
|
||||
|
||||
func JobMonthlyBookingReport() error {
|
||||
_ = godotenv.Load()
|
||||
db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL")), &gorm.Config{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to the database %w", err)
|
||||
}
|
||||
// service, _ := booking.NewService(db, nil, ps)
|
||||
// period := "monthly"
|
||||
// month := int(now.Month())
|
||||
// year := now.Year()
|
||||
|
||||
now := time.Now()
|
||||
log.Println("Start Monthly Booking Report job at:", now)
|
||||
// err = service.BuildReport(service.Report(period, month, year), period, month, year)
|
||||
|
||||
ps, err := pdf.NewPdfClient(
|
||||
os.Getenv("HTMLDOCS_PROJECT_ID"),
|
||||
os.Getenv("HTMLDOCS_REPORT_PROJECT_ID"),
|
||||
os.Getenv("HTMLDOCS_URL"),
|
||||
os.Getenv("HTMLDOCS_KEY"),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error starting pdf service %w", err)
|
||||
}
|
||||
|
||||
service, _ := booking.NewService(db, nil, ps)
|
||||
period := "monthly"
|
||||
month := int(now.Month())
|
||||
year := now.Year()
|
||||
|
||||
err = service.BuildReport(service.Report(period, month, year), period, month, year)
|
||||
|
||||
log.Printf("Executed Monthly Booking Report job at %v with errors: %s:", time.Now().Format(time.DateTime), err)
|
||||
return err
|
||||
}
|
||||
// log.Printf("Executed Monthly Booking Report job at %v with errors: %s:", time.Now().Format(time.DateTime), err)
|
||||
// return err
|
||||
// }
|
||||
|
|
|
|||
Loading…
Reference in a new issue