I am building an iOS app using Rubymotion. I need to find a way to create and run "background jobs" (like Resque) in my app. What I mean by that is that when the user for example add a new task, instead of sending it directly to the server I want to wait for when the Internet connection is good.
Is there a gem or a solution for this?
Thankful for all clues!
If you want to have something like background jobs, you can take a look at NSQueueOperation and NSOperation.
Basically a NSQueueOperation is like a container containing NSOperation.
An NSOperation is a sort of a job. But there is no persistence. Thus, if a NSOperations is enqueued in a NSQueueOperation and if you restart your application, the NSQueueOperation will be empty.
But in your case, it might be a little overkill. Instead you should listen to the Reachability notifications. You can use either the Apple's implemtation or this one(More powerful). When you device goes online, get the list of your items which haven't been created/updated on your remote service. You can find them by looking for their id or any other flags which could be used to determine their state.
For instance if a record doesn't have any id yet, it means it hasn't been created on your remote service yet. In the same way, you can use an updated(Boolean)
attribute to know if an object has to be updated on your remote service.
For each of them, make a HTTP call to your api, and once your request if finished, update your object to reflect the changes (set the id, remove your flags ect ...)
hope it helps