Skip to content

AssemblyLine is a library for easily writing workflows.

License

Notifications You must be signed in to change notification settings

1amageek/AssemblyLine

Repository files navigation

AssemblyLine

Version Platform

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

Why

Processing flow of data becomes complicated year by year. Until a few years ago I just took a picture and uploaded it. Recently, it passes through multiple flow, processing photos and processing meta information, face recognition.

Processing of data does not always succeed in all. Because mobile has an unstable factor.

  1. Network disconnection
  2. Insufficient memory
  3. Insufficient storage

It is necessary to have a method to make each processing independent and to process it simple.

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published