Skip to content

reddavis/Kyu

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kyu

Kyu is a stupidly simple, persistant, queue system.

Requirements

  • iOS 15.0+
  • macOS 12.0+

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/reddavis/Kyu", from: "3.0.0-beta.1")
]

Usage

Kyu has two parts to it; The Kyu, which manages job state and execution and the Job which does the actual work.

The Job

A job must simply conform to the Job and Codable protocol.

A simple "Append new line to end of file" job could look something like:

final class AppendNewLineJob: Job
{
    let id: UUID
    var maximumNumberOfRetries: Int { 5 }
    var numberOfRetries = 0
    var executionDate = Date()
    
    let fileURL: URL
    let string: String
    
    // MARK: Initialization
    
    init(fileURL: URL, string: String)
    {
        self.id = UUID()
        self.fileURL = fileURL
        self.string = string
    }
    
    // MARK: Job
    
    func execute() async throws
    {
        let fileHandle = try FileHandle(forWritingTo: self.fileURL)
        try fileHandle.seekToEnd()
        fileHandle.write("\(self.string)\n".data(using: .utf8)!)
        fileHandle.closeFile()
    }
}

The Kyu

The Kyu manages and executes jobs. It take a URL parameter, which is where it will persist the jobs.

let url = URL(string: ...)!
self.kyu = try Kyu<AppendNewLineJob>(url: url)

let job = AppendNewLineJob(
    fileURL: fileURL, 
    string: "a string to append"
)
try await kyu.add(job: job)

About

Kyu is persistent queue system in Swift.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.6%
  • Objective-C 1.4%