MCPcopy
hub / github.com/apache/answer / Run

Method Run

internal/base/cron/cron.go:62–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60}
61
62func (s *ScheduledTaskManager) Run() {
63 log.Infof("cron job manager start")
64
65 s.questionService.SitemapCron(context.Background())
66 c := cron.New()
67 _, err := c.AddFunc("0 */1 * * *", func() {
68 ctx := context.Background()
69 log.Infof("sitemap cron execution")
70 s.questionService.SitemapCron(ctx)
71 })
72 if err != nil {
73 log.Error(err)
74 }
75
76 _, err = c.AddFunc("0 */1 * * *", func() {
77 ctx := context.Background()
78 log.Infof("refresh hottest cron execution")
79 s.questionService.RefreshHottestCron(ctx)
80 })
81 if err != nil {
82 log.Error(err)
83 }
84
85 // Check for expired user suspensions every 10 minutes
86 _, err = c.AddFunc("*/10 * * * *", func() {
87 ctx := context.Background()
88 log.Infof("checking expired user suspensions")
89 err := s.userAdminService.CheckAndUnsuspendExpiredUsers(ctx)
90 if err != nil {
91 log.Errorf("failed to check expired user suspensions: %v", err)
92 }
93 })
94 if err != nil {
95 log.Error(err)
96 }
97
98 if s.serviceConfig.CleanUpUploads {
99 log.Infof("clean up uploads cron enabled")
100
101 conf := s.serviceConfig
102 _, err = c.AddFunc(fmt.Sprintf("0 */%d * * *", conf.CleanOrphanUploadsPeriodHours), func() {
103 log.Infof("clean orphan upload files cron execution")
104 s.fileRecordService.CleanOrphanUploadFiles(context.Background())
105 })
106 if err != nil {
107 log.Error(err)
108 }
109
110 _, err = c.AddFunc(fmt.Sprintf("0 0 */%d * *", conf.PurgeDeletedFilesPeriodDays), func() {
111 log.Infof("purge deleted files cron execution")
112 s.fileRecordService.PurgeDeletedFiles(context.Background())
113 })
114 if err != nil {
115 log.Error(err)
116 }
117 }
118 c.Start()
119}

Callers 15

TestMainFunction · 0.80
TestBasicOperationsFunction · 0.80
TestTransactionsFunction · 0.80
TestConcurrencyFunction · 0.80
TestGetQuestionLinkFunction · 0.80
TestGetAvatarURLFunction · 0.80
TestResizeFunction · 0.80
createMainGoFileFunction · 0.80
downloadGoModFileFunction · 0.80
copyUIFilesFunction · 0.80
buildUIFunction · 0.80

Calls 5

RefreshHottestCronMethod · 0.80
PurgeDeletedFilesMethod · 0.80
SitemapCronMethod · 0.45

Tested by 9

TestMainFunction · 0.64
TestBasicOperationsFunction · 0.64
TestTransactionsFunction · 0.64
TestConcurrencyFunction · 0.64
TestGetQuestionLinkFunction · 0.64
TestGetAvatarURLFunction · 0.64
TestResizeFunction · 0.64
TestQueue_SendCloseRaceFunction · 0.64
TestMainFunction · 0.64