diff options
author | 2023-02-13 18:40:48 +0000 | |
---|---|---|
committer | 2023-02-13 18:40:48 +0000 | |
commit | acc95923da555b2bf17a5638e62e533218c5840a (patch) | |
tree | 7df5d0636137efa5b49298a8f0ced81d35767a5b /internal/media/cron.go | |
parent | [docs] move federating with gotosocial documentation into single file (#1494) (diff) | |
download | gotosocial-acc95923da555b2bf17a5638e62e533218c5840a.tar.xz |
[performance] processing media and scheduled jobs improvements (#1482)
* replace media workers with just runners.WorkerPool, move to state structure, use go-sched for global task scheduling
* improved code comment
* fix worker tryUntil function, update go-runners/go-sched
* make preprocess functions package public, use these where possible to stop doubled up processing
* remove separate emoji worker pool
* limit calls to time.Now() during media preprocessing
* use Processor{} to manage singular runtime of processing media
* ensure workers get started when media manager is used
* improved error setting in processing media, fix media test
* port changes from processingmedia to processing emoji
* finish code commenting
* finish code commenting and comment-out client API + federator worker pools until concurrency worker pools replaced
* linterrrrrrrrrrrrrrrr
---------
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/media/cron.go')
-rw-r--r-- | internal/media/cron.go | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/internal/media/cron.go b/internal/media/cron.go deleted file mode 100644 index e32a63661..000000000 --- a/internal/media/cron.go +++ /dev/null @@ -1,73 +0,0 @@ -/* - GoToSocial - Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -package media - -import ( - "context" - "fmt" - "time" - - "github.com/robfig/cron/v3" - "github.com/superseriousbusiness/gotosocial/internal/config" - "github.com/superseriousbusiness/gotosocial/internal/log" -) - -type cronLogger struct{} - -func (l *cronLogger) Info(msg string, keysAndValues ...interface{}) { - log.Info("media manager cron logger: ", msg, keysAndValues) -} - -func (l *cronLogger) Error(err error, msg string, keysAndValues ...interface{}) { - log.Error("media manager cron logger: ", err, msg, keysAndValues) -} - -func scheduleCleanup(m *manager) error { - pruneCtx, pruneCancel := context.WithCancel(context.Background()) - - c := cron.New(cron.WithLogger(new(cronLogger))) - defer c.Start() - - if _, err := c.AddFunc("@midnight", func() { - if err := m.PruneAll(pruneCtx, config.GetMediaRemoteCacheDays(), true); err != nil { - log.Error(err) - return - } - }); err != nil { - pruneCancel() - return fmt.Errorf("error starting media manager cleanup job: %s", err) - } - - m.stopCronJobs = func() error { - // Try to stop jobs gracefully by waiting til they're finished. - stopCtx := c.Stop() - - select { - case <-stopCtx.Done(): - log.Infof("media manager: cron finished jobs and stopped gracefully") - case <-time.After(1 * time.Minute): - log.Warnf("media manager: cron didn't stop after 60 seconds, force closing jobs") - pruneCancel() - } - - return nil - } - - return nil -} |