Skip to content

Commit

Permalink
refactor: create queue reader that reads from the file system
Browse files Browse the repository at this point in the history
Reads the pending tasks queue from the filesystem.

This reader is not being executed in the SDK yet. More code needs to be made before we enable any of the file system code (reader and writer).

commit-id:0a5ec736
  • Loading branch information
levibostian committed Feb 3, 2024
1 parent a9d170a commit e848b33
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Wendy/Classes/Store/FileSystem/FileSystemQueueReader.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// FileSystemQueueReader.swift
// Wendy
//
// Created by Levi Bostian on 2/3/24.
//

import Foundation

public class FileSystemQueueReader: QueueReader {

private var queue: FileSystemQueue {
return FileSystemQueueImpl.shared
}

public func getAllTasks() -> [PendingTask] {
return queue.queue
}

public func getTaskByTaskId(_ taskId: Double) -> PendingTask? {
return queue.queue.first(where: { $0.taskId == taskId })
}

public func getNextTaskToRun(_ lastSuccessfulOrFailedTaskId: Double, filter: RunAllTasksFilter?) -> PendingTask? {
var potentialTasksToRun = queue.queue
potentialTasksToRun = potentialTasksToRun.filter {
guard let taskId = $0.taskId else { return false }
return taskId > lastSuccessfulOrFailedTaskId
}

if let filter = filter {
switch filter {
case .group(let groupId):
potentialTasksToRun = potentialTasksToRun.filter {
$0.groupId == groupId
}
}
}

return potentialTasksToRun.first
}
}

0 comments on commit e848b33

Please sign in to comment.