Pelican 2.0.0

Pelican 2.0.0

Maintained by Robert Manson, Erik Strottmann.

Pelican 2.0.0

  • By
  • bd755bf4f7e672000cab58c4b721a8cdbe22a839


Build Status Version License Platform

Pelican is a persisted batching library useful for log rolling, event logging or doing other periodic background processing.


The following is an example of setting up custom event logging, for example to your own API using Pelican to batch upload tasks.

protocol AppEvents: PelicanGroupable {
    var eventName: String { get }
    var timeStamp: Date { get }

// Batch all app events together into the same group
extension AppEvents {
    // Used to group events so they can batched
    var group: String {
        return "Example App Events"

    /// Pelican will call `processGroup` on a background thread. You should implement it to do whatever processing is 
    /// relevant to your application. Below is a sample implementation that sends application events as a batch.
    static func processGroup(tasks: [PelicanBatchableTask], didComplete: @escaping ((PelicanProcessResult) -> Void)) {
        // Construct JSON to pass to your API.
        let postData = Data()
        API.shared.postEvents(json: postData) { error in
            if error == nil {
            } else {
                // Retry will call process group again until succesful
                didComplete(PelicanProcessResult.retry(delay: 0))

// Using compiler generated conformance since PelicanBatchableTask refines Codable
struct LogInEvent: PelicanBatchableTask, AppEvents {
    let eventName: String = "Log In"
    let timeStamp: Date
    let userName: String

    init(userName: String) {
        self.timeStamp = Date()
        self.userName = userName

    // PelicanBatchableTask conformance, used to read and store task to storage
    static let taskType: String = String(describing: LogInEvent.self)

Register your batchable tasks and initialize Pelican as soon as possible, for example in application(_ application: UIApplication, didFinishLaunchingWithOptions...

var tasks = Pelican.RegisteredTasks()
tasks.register(for: LogInEvent.self)

Pelican.initialize(tasks: tasks)

When the user performs an event we log it with Pelican, after 5 seconds events are grouped and processGroup is called to send them.

Pelican.shared.gulp(task: LogInEvent(userName: "Ender Wiggin"))


Pelican requires Swift 5 or higher.


Pelican is available through CocoaPods, and requires CocoaPods 1.7.0 or higher.

To install Pelican, add the following line to your Podfile:

pod 'Pelican'


[email protected]


Pelican is available under the MIT license. See the LICENSE file for more info.