Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/bootstrap/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func InitTaskManager() {
op.RegisterSettingChangingCallback(func() {
fs.MoveTaskManager.SetWorkersNumActive(taskFilterNegative(setting.GetInt(conf.TaskMoveThreadsNum, conf.Conf.Tasks.Move.Workers)))
})
fs.SyncTaskManager = tache.NewManager[*fs.SyncTask](tache.WithWorks(1), tache.WithMaxRetry(0))
tool.DownloadTaskManager = tache.NewManager[*tool.DownloadTask](tache.WithWorks(setting.GetInt(conf.TaskOfflineDownloadThreadsNum, conf.Conf.Tasks.Download.Workers)), tache.WithPersistFunction(db.GetTaskDataFunc("download", conf.Conf.Tasks.Download.TaskPersistant), db.UpdateTaskDataFunc("download", conf.Conf.Tasks.Download.TaskPersistant)), tache.WithMaxRetry(conf.Conf.Tasks.Download.MaxRetry))
op.RegisterSettingChangingCallback(func() {
tool.DownloadTaskManager.SetWorkersNumActive(taskFilterNegative(setting.GetInt(conf.TaskOfflineDownloadThreadsNum, conf.Conf.Tasks.Download.Workers)))
Expand Down
3 changes: 2 additions & 1 deletion internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var db *gorm.DB

func Init(d *gorm.DB) {
db = d
err := AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem), new(model.SearchNode), new(model.TaskItem), new(model.SSHPublicKey))
err := AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem), new(model.SearchNode),
new(model.TaskItem), new(model.SSHPublicKey), new(model.SyncerTaskArgs))
if err != nil {
log.Fatalf("failed migrate database: %s", err.Error())
}
Expand Down
38 changes: 38 additions & 0 deletions internal/db/syncer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package db

import (
"github.com/OpenListTeam/OpenList/v4/internal/model"
"github.com/pkg/errors"
)

func CreateSyncerTaskArgs(syncerTaskArgs *model.SyncerTaskArgs) error {
return errors.WithStack(db.Create(syncerTaskArgs).Error)
}

func UpdateSyncerTaskArgs(syncerTaskArgs *model.SyncerTaskArgs) error {
return errors.WithStack(db.Save(syncerTaskArgs).Error)
}

func DeleteSyncerTaskArgsById(id uint) error {
return errors.WithStack(db.Delete(&model.SyncerTaskArgs{}, id).Error)
}

func GetSyncerTaskArgsById(id uint) (*model.SyncerTaskArgs, error) {
var syncerTaskArgs model.SyncerTaskArgs
syncerTaskArgs.ID = id
if err := db.First(&syncerTaskArgs).Error; err != nil {
return nil, errors.WithStack(err)
}
return &syncerTaskArgs, nil
}

func GetSyncerTaskArgs(pageIndex, pageSize int) (syncTaskArgList []model.SyncerTaskArgs, count int64, err error) {
syncerTaskArgsDB := db.Model(&model.SyncerTaskArgs{})
if err := syncerTaskArgsDB.Count(&count).Error; err != nil {
return nil, 0, errors.Wrapf(err, "failed get syncTaskArgList count")
}
if err := syncerTaskArgsDB.Order(columnName("id")).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&syncTaskArgList).Error; err != nil {
return nil, 0, errors.Wrapf(err, "failed get find syncTaskArgList")
}
return syncTaskArgList, count, nil
}
8 changes: 8 additions & 0 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,11 @@ func PutURL(ctx context.Context, path, dstName, urlStr string) error {
}
return op.PutURL(ctx, storage, dstDirActualPath, dstName, urlStr)
}

func Syncer(ctx context.Context, syncerArgs model.SyncerTaskArgs) (task.TaskExtensionInfo, error) {
res, err := _syncer(ctx, syncerArgs)
if err != nil {
log.Errorf("failed sync %s to %s: %+v", syncerArgs.SrcPath, syncerArgs.DstPath, err)
}
return res, err
}
Loading
Loading