diff --git a/controller/sync_controller.go b/controller/sync_controller.go index 509801f..c5b0deb 100644 --- a/controller/sync_controller.go +++ b/controller/sync_controller.go @@ -29,6 +29,7 @@ func handleSync(ctx *gin.Context) { // Add to queue log.Infof("Adding %s to queue", sourceDetails.Account) internal.AddTask(sourceDetails, destinationDetails) + ctx.HTML(200, "success.html", "added to queue") // log.Infof("Syncing %s to %s", sourceDetails.Account, destinationDetails.Account) diff --git a/internal/queue.go b/internal/queue.go index 509f2a6..ded158b 100644 --- a/internal/queue.go +++ b/internal/queue.go @@ -47,25 +47,8 @@ func InitQueue() { SetupLogger() queue = list.New() taskChan = make(chan Task) - for i := 0; i < 10; i++ { - addOneTask() - } - go processPendingTasks() -} -func addOneTask() { - task := &Task{ - ID: queue.Len() + 1, - SourceAccount: "jomo", - SourceServer: "imap.gmail.com", - DestinationAccount: "emin", - DestinationServer: "imap.yandex.com", - Status: "Pending", - } - queue.PushFront(task) - go func() { - taskChan <- *task - }() + go processPendingTasks() } func AddTask(sourceDetails, destinationDetails Credentials) { diff --git a/internal/sync.go b/internal/sync.go index 43daa3e..4cb0362 100644 --- a/internal/sync.go +++ b/internal/sync.go @@ -9,6 +9,8 @@ import ( func syncIMAP(details *Task) error { + details.Status = "In Progress" + cmd := exec.Command("imapsync", "--host1", details.SourceServer, "--user1", details.SourceAccount, "--password1", details.SourcePassword, "--host2", details.DestinationServer, "--user2", details.DestinationAccount, "--password2", details.DestinationPassword) var stdBuffer bytes.Buffer mw := io.MultiWriter(os.Stdout, &stdBuffer) diff --git a/internal/sync_loop.go b/internal/sync_loop.go index 67df49e..29eb75b 100644 --- a/internal/sync_loop.go +++ b/internal/sync_loop.go @@ -9,12 +9,10 @@ func processPendingTasks() { // If there are no pending tasks, wait for a new task to be added if task == nil { - task := <-taskChan - simulateSyncIMAP(&task) continue } - simulateSyncIMAP(task) + syncIMAP(task) time.Sleep(2000 * time.Millisecond) } } @@ -28,10 +26,3 @@ func getFirstPendingTask() *Task { } return nil } - -func simulateSyncIMAP(details *Task) error { - details.Status = "In Progress" - time.Sleep(5000 * time.Millisecond) - details.Status = "Done" - return nil -} diff --git a/templates/admin.html b/templates/admin.html index d620c54..f5af2b0 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -110,7 +110,7 @@