basedgod basedgod - 1 year ago 181
Swift Question

Scheduled tasks in Server-Side Swift (Kitura, Vapor, Zewo, etc.)

Is there a possibility of schedulding tasks on any server-side swift framework? Preferably Kitura...

I need to schedule tasks for example wiping a database everyday at 3AM.

Thank you.

Answer Source

In Kitura at least, we don't provide an special functionality for that.

One thing you can consider using is Dispatch, which will work very well for your example of deleting the database everyday at 3AM. You can create a DispatchSourceTimer that dispatches some code after some interval once or repeatedly.

DispatchSourceTimer.scheduleOneshot(deadline: DispatchTimer, leeway: DispatchTimeInterval)
DispatchSourceTimer.scheduleRepeating(deadline: DispatchTime, interval: DispatchTimeInterval, leeway: DispatchTimeInterval)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download