support config clone timeout, do upgrades
This commit is contained in:
2
internal/cache/cache.go
vendored
2
internal/cache/cache.go
vendored
@ -122,7 +122,7 @@ func (c *Cache) Read() error {
|
||||
d.Decode(c)
|
||||
|
||||
// Perform migrations
|
||||
err, migrated := c.doMigrations()
|
||||
migrated, err := c.doMigrations()
|
||||
if err != nil {
|
||||
c.log.Error("Failed to run cache migrations",
|
||||
c.log.Args(
|
||||
|
14
internal/cache/cache_migrations.go
vendored
14
internal/cache/cache_migrations.go
vendored
@ -11,7 +11,7 @@ import (
|
||||
|
||||
// Migrations funcs should return errors along with
|
||||
// number of records updated
|
||||
type migrationFunc func(c *Cache) (error, int)
|
||||
type migrationFunc func(c *Cache) (int, error)
|
||||
|
||||
// Registry of migrations by version
|
||||
var migrations = map[string]map[string]migrationFunc{
|
||||
@ -24,20 +24,20 @@ var migrations = map[string]map[string]migrationFunc{
|
||||
// of cache read from disk.
|
||||
// Does not check to ensure migrations were successful,
|
||||
// only checks if a version has been achieved
|
||||
func (c *Cache) DoMigrations() (error, int) {
|
||||
func (c *Cache) DoMigrations() (int, error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
return c.doMigrations()
|
||||
}
|
||||
|
||||
func (c *Cache) doMigrations() (error, int) {
|
||||
func (c *Cache) doMigrations() (int, error) {
|
||||
var errs error
|
||||
var migrated int
|
||||
for version, migrationFuncs := range migrations {
|
||||
var funcMigrated int
|
||||
if semver.Compare(c.CacheVersion, version) < 0 {
|
||||
for name, migration := range migrationFuncs {
|
||||
err, numMigrated := migration(c)
|
||||
numMigrated, err := migration(c)
|
||||
if err != nil {
|
||||
errs = errors.Join(
|
||||
errs,
|
||||
@ -57,10 +57,10 @@ func (c *Cache) doMigrations() (error, int) {
|
||||
migrated += funcMigrated
|
||||
}
|
||||
|
||||
return errs, migrated
|
||||
return migrated, errs
|
||||
}
|
||||
|
||||
func v010_aliases(c *Cache) (error, int) {
|
||||
func v010_aliases(c *Cache) (int, error) {
|
||||
var aliasesMigrated int
|
||||
var errs error
|
||||
for i, a := range c.Aliases {
|
||||
@ -74,5 +74,5 @@ func v010_aliases(c *Cache) (error, int) {
|
||||
aliasesMigrated++
|
||||
}
|
||||
}
|
||||
return errs, aliasesMigrated
|
||||
return aliasesMigrated, errs
|
||||
}
|
||||
|
4
internal/cache/projects_git.go
vendored
4
internal/cache/projects_git.go
vendored
@ -9,14 +9,12 @@ import (
|
||||
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/projects"
|
||||
)
|
||||
|
||||
const gitCloneTimeoutSecs = 60
|
||||
|
||||
// Will either read in the current repo, preparing a report
|
||||
// on its current state, or will clone the project if it has not
|
||||
// already been cloned in its path
|
||||
func (c *Cache) OpenProject(ctx context.Context, project *projects.Project) *git.Repository {
|
||||
path := c.GetProjectPath(project)
|
||||
cloneCtx, cncl := context.WithDeadline(ctx, time.Now().Add(gitCloneTimeoutSecs*time.Second))
|
||||
cloneCtx, cncl := context.WithDeadline(ctx, time.Now().Add(c.config.GetCloneTimeout()))
|
||||
defer cncl()
|
||||
|
||||
var repo *git.Repository
|
||||
|
Reference in New Issue
Block a user