mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +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",
|
Name: "Monthly Booking Report",
|
||||||
Schedule: "minute",
|
Schedule: "minute",
|
||||||
//Schedule: "monthly",
|
//Schedule: "monthly",
|
||||||
Action: cron.JobMonthlyBookingReport,
|
// Action: cron.JobMonthlyBookingReport,
|
||||||
})
|
})
|
||||||
|
|
||||||
go scheduler.Start()
|
go scheduler.Start()
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,32 @@
|
||||||
package cron
|
package cron
|
||||||
|
|
||||||
import (
|
// func JobMonthlyBookingReport() error {
|
||||||
"fmt"
|
// _ = godotenv.Load()
|
||||||
"log"
|
// db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL")), &gorm.Config{})
|
||||||
"os"
|
// if err != nil {
|
||||||
"time"
|
// return fmt.Errorf("error connecting to the database %w", err)
|
||||||
|
// }
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
// now := time.Now()
|
||||||
"gorm.io/driver/postgres"
|
// log.Println("Start Monthly Booking Report job at:", now)
|
||||||
"gorm.io/gorm"
|
|
||||||
|
|
||||||
"github.com/rjNemo/rentease/internal/driver/pdf"
|
// ps, err := pdf.NewPdfClient(
|
||||||
"github.com/rjNemo/rentease/internal/service/booking"
|
// 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 {
|
// service, _ := booking.NewService(db, nil, ps)
|
||||||
_ = godotenv.Load()
|
// period := "monthly"
|
||||||
db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL")), &gorm.Config{})
|
// month := int(now.Month())
|
||||||
if err != nil {
|
// year := now.Year()
|
||||||
return fmt.Errorf("error connecting to the database %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now()
|
// err = service.BuildReport(service.Report(period, month, year), period, month, year)
|
||||||
log.Println("Start Monthly Booking Report job at:", now)
|
|
||||||
|
|
||||||
ps, err := pdf.NewPdfClient(
|
// log.Printf("Executed Monthly Booking Report job at %v with errors: %s:", time.Now().Format(time.DateTime), err)
|
||||||
os.Getenv("HTMLDOCS_PROJECT_ID"),
|
// return err
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue