Skip to content

AssemblyLine is a library for easily writing workflows.

License

Notifications You must be signed in to change notification settings

SirComet/AssemblyLine

 
 

Repository files navigation

AssemblyLine

Version Platform

AssemblyLine processes several tasks continuously in the background. Discard tasks that failed during execution during execution.

Usage 👻

Take example of Tesla's factory.

Define Status.

enum ModelXStatus: StatusProtocol {
    case spec
    case assembly
    case paint
}

Define Error.

enum ModelXError: Error {
    case invalid
}

Processable protocol.

class ModelX: Processable {
    
    typealias Status = ModelXStatus
    
    var error: Error?
    var id: String
    var status: Status
    var workItem: DispatchWorkItem?
    var isAssembled: Bool = false
    var color: UIColor?
    
    init() {
        self.id = UUID().uuidString
        self.status = .spec        
    }
    
    // Processing when an error occurs
    func dispose(_ error: Error?) {
        
    }
}
struct ModelXPackage: Packageable {
    var products: [ModelX]
}
// Define workflow steps
let assembly: Step<ModelX> = Step({ (product) -> ModelX in
    product.isAssembled = true
    return product
})

// Define workflow steps
let paint: Step<ModelX> = Step({ (product) -> ModelX in
    product.color = .white
    return product
})

// Making a manufacturing line to do workflow
let line: Line<ModelX, ModelXPackage> = Line(workflow: [assembly, paint])

// Generate 10 ModelX
(0..<10).forEach({ (index) in
    let product: ModelX = ModelX()
    line.generate(product)
})

// Packaging
line.packing { (products, isStopped) in    
    if isStopped {
        print("Line is stopped")
        return
    }
    let package = ModelXPackage(products: products)
}

About

AssemblyLine is a library for easily writing workflows.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 81.8%
  • Ruby 14.1%
  • Objective-C 4.1%