mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Storage buckets, indexer names, the bleve analyzer, the lock prefix, SSH host keys, the markdown front-matter key, the container data paths, the RPM repo id and the API security scheme all read as this product now, and app.example.ini matches the code again. The upstream maintainer list and the changelog generator config went with the release history they belonged to, and the citation comments state the fact rather than link the issue. Three inert rules turn out to have been inert because they named a module path this tree does not use: gci grouped no first-party imports under prefix(), and depguard let models/migrations import models and modules/structs. They now name github.com/hanzoai/git. The config example also documented .gitea/workflows while the code has read .hanzo/workflows for some time. The authorized_keys marker follows the delegate-hook precedent: the new name is written and the old one is still recognised, because a marker we do not know is copied through as a hand-added key and leaves a revoked key authorized. The stored user_setting key keeps its value; only a migration may change that. Co-authored-by: Hanzo Dev <[email protected]>
246 lines
7.8 KiB
Go
246 lines
7.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cron
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
activities_model "github.com/hanzoai/git/models/activities"
|
|
"github.com/hanzoai/git/models/system"
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
"github.com/hanzoai/git/modules/git/gitcmd"
|
|
issue_indexer "github.com/hanzoai/git/modules/indexer/issues"
|
|
"github.com/hanzoai/git/modules/setting"
|
|
"github.com/hanzoai/git/modules/updatechecker"
|
|
asymkey_service "github.com/hanzoai/git/services/asymkey"
|
|
repo_service "github.com/hanzoai/git/services/repository"
|
|
archiver_service "github.com/hanzoai/git/services/repository/archiver"
|
|
user_service "github.com/hanzoai/git/services/user"
|
|
)
|
|
|
|
func registerDeleteInactiveUsers() {
|
|
RegisterTaskFatal("delete_inactive_accounts", &OlderThanConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@annually",
|
|
},
|
|
OlderThan: time.Minute * time.Duration(setting.Service.ActiveCodeLives),
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
return user_service.DeleteInactiveUsers(ctx, olderThanConfig.OlderThan)
|
|
})
|
|
}
|
|
|
|
func registerDeleteRepositoryArchives() {
|
|
RegisterTaskFatal("delete_repo_archives", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@annually",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return archiver_service.DeleteRepositoryArchives(ctx)
|
|
})
|
|
}
|
|
|
|
func registerGarbageCollectRepositories() {
|
|
type RepoHealthCheckConfig struct {
|
|
BaseConfig
|
|
Timeout time.Duration
|
|
Args []string `delim:" "`
|
|
}
|
|
RegisterTaskFatal("git_gc_repos", &RepoHealthCheckConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
},
|
|
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
|
|
Args: setting.Git.GCArgs,
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
rhcConfig := config.(*RepoHealthCheckConfig)
|
|
// the git args are set by config, they can be safe to be trusted
|
|
return repo_service.GitGcRepos(ctx, rhcConfig.Timeout, gitcmd.ToTrustedCmdArgs(rhcConfig.Args))
|
|
})
|
|
}
|
|
|
|
func registerRewriteAllPublicKeys() {
|
|
RegisterTaskFatal("resync_all_sshkeys", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return asymkey_service.RewriteAllPublicKeys(ctx)
|
|
})
|
|
}
|
|
|
|
func registerRewriteAllPrincipalKeys() {
|
|
RegisterTaskFatal("resync_all_sshprincipals", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return asymkey_service.RewriteAllPrincipalKeys(ctx)
|
|
})
|
|
}
|
|
|
|
func registerRepositoryUpdateHook() {
|
|
RegisterTaskFatal("resync_all_hooks", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return repo_service.SyncRepositoryHooks(ctx)
|
|
})
|
|
}
|
|
|
|
func registerReinitMissingRepositories() {
|
|
RegisterTaskFatal("reinit_missing_repos", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return repo_service.ReinitMissingRepositories(ctx)
|
|
})
|
|
}
|
|
|
|
func registerDeleteMissingRepositories() {
|
|
RegisterTaskFatal("delete_missing_repos", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, user *user_model.User, _ Config) error {
|
|
return repo_service.DeleteMissingRepositories(ctx, user)
|
|
})
|
|
}
|
|
|
|
func registerRemoveRandomAvatars() {
|
|
RegisterTaskFatal("delete_generated_repository_avatars", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return repo_service.RemoveRandomAvatars(ctx)
|
|
})
|
|
}
|
|
|
|
func registerDeleteOldActions() {
|
|
RegisterTaskFatal("delete_old_actions", &OlderThanConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 168h",
|
|
},
|
|
OlderThan: 365 * 24 * time.Hour,
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
return activities_model.DeleteOldActions(ctx, olderThanConfig.OlderThan)
|
|
})
|
|
}
|
|
|
|
func registerUpdateGitChecker() {
|
|
type UpdateCheckerConfig struct {
|
|
BaseConfig
|
|
HTTPEndpoint string
|
|
}
|
|
RegisterTaskFatal("update_checker", &UpdateCheckerConfig{
|
|
BaseConfig: BaseConfig{
|
|
// Off by default: our releases ship via the hanzoai/git CR pipeline,
|
|
// not an upstream feed — phoning one would compare against
|
|
// the WRONG product's versions (and leak telemetry upstream).
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 168h",
|
|
},
|
|
HTTPEndpoint: "https://github.com/hanzoai/git/releases.atom",
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
updateCheckerConfig := config.(*UpdateCheckerConfig)
|
|
return updatechecker.GitUpdateChecker(updateCheckerConfig.HTTPEndpoint)
|
|
})
|
|
}
|
|
|
|
func registerDeleteOldSystemNotices() {
|
|
RegisterTaskFatal("delete_old_system_notices", &OlderThanConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 168h",
|
|
},
|
|
OlderThan: 365 * 24 * time.Hour,
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
return system.DeleteOldSystemNotices(ctx, olderThanConfig.OlderThan)
|
|
})
|
|
}
|
|
|
|
type GCLFSConfig struct {
|
|
BaseConfig
|
|
OlderThan time.Duration
|
|
LastUpdatedMoreThanAgo time.Duration
|
|
NumberToCheckPerRepo int64
|
|
ProportionToCheckPerRepo float64
|
|
}
|
|
|
|
func registerGCLFS() {
|
|
if !setting.LFS.StartServer {
|
|
return
|
|
}
|
|
|
|
RegisterTaskFatal("gc_lfs", &GCLFSConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 24h",
|
|
},
|
|
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
|
|
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
|
|
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
|
|
// changes in new branches that might lead to lfs objects becoming temporarily unassociated with git
|
|
// objects.
|
|
//
|
|
// It is likely that a week is potentially excessive but it should definitely be enough that any
|
|
// unassociated LFS object is genuinely unassociated.
|
|
OlderThan: 24 * time.Hour * 7,
|
|
|
|
// Only GC things that haven't been looked at in the past 3 days
|
|
LastUpdatedMoreThanAgo: 24 * time.Hour * 3,
|
|
NumberToCheckPerRepo: 100,
|
|
ProportionToCheckPerRepo: 0.6,
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
gcLFSConfig := config.(*GCLFSConfig)
|
|
return repo_service.GarbageCollectLFSMetaObjects(ctx, repo_service.GarbageCollectLFSMetaObjectsOptions{
|
|
AutoFix: true,
|
|
OlderThan: time.Now().Add(-gcLFSConfig.OlderThan),
|
|
UpdatedLessRecentlyThan: time.Now().Add(-gcLFSConfig.LastUpdatedMoreThanAgo),
|
|
})
|
|
})
|
|
}
|
|
|
|
func registerRebuildIssueIndexer() {
|
|
RegisterTaskFatal("rebuild_issue_indexer", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@annually",
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
return issue_indexer.PopulateIssueIndexer(ctx)
|
|
})
|
|
}
|
|
|
|
func initExtendedTasks() {
|
|
registerDeleteInactiveUsers()
|
|
registerDeleteRepositoryArchives()
|
|
registerGarbageCollectRepositories()
|
|
registerRewriteAllPublicKeys()
|
|
registerRewriteAllPrincipalKeys()
|
|
registerRepositoryUpdateHook()
|
|
registerReinitMissingRepositories()
|
|
registerDeleteMissingRepositories()
|
|
registerRemoveRandomAvatars()
|
|
registerDeleteOldActions()
|
|
registerUpdateGitChecker()
|
|
registerDeleteOldSystemNotices()
|
|
registerGCLFS()
|
|
registerRebuildIssueIndexer()
|
|
}
|