Commit 0f39acf9 authored by laurent l's avatar laurent l

add background jobs

parent ad797a31
import { BackgroundFetch } from "nativescript-background-fetch"
import { UpdateAccountsJob } from './update-accounts-job'
export class BackgroundJobs {
public setupScheduleJob() {
BackgroundFetch.registerHeadlessTask(() => {
console.log('[BackgroundFetch] Demo Headless Task')
updateAccounts()
BackgroundFetch.finish()
})
let updateAccounts = () => {
new UpdateAccountsJob().updateAccounts()
}
}
}
import { Database } from '../models/'
export declare class BackgroundJobs {
public setupScheduleJob(app: any): this
}
import { Database } from '../../models/'
import { BackgroundFetch } from "nativescript-background-fetch";
import { UpdateAccountsJob } from './update-accounts-job'
var MBAAppDelegate = (UIResponder as any).extend(
{
applicationPerformFetchWithCompletionHandler: function(application: UIApplication, completionHandler: any) {
console.log('- AppDelegate Rx Fetch event');
BackgroundFetch.performFetchWithCompletionHandler(completionHandler, application.applicationState);
}
},
{
name: 'MBAAppDelegate',
protocols: [UIApplicationDelegate]
}
);
MBAAppDelegate.ObjCProtocols = [UIApplicationDelegate];
export class BackgroundJobs {
public setupScheduleJob(app: any) {
app.ios.delegate = MBAAppDelegate;
}
}
import { Database, Portal, Account } from '../../models/'
import { BackgroundFetch } from "nativescript-background-fetch"
export class UpdateAccountsJob {
public setup() {
BackgroundFetch.configure({
minimumFetchInterval: 15,
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true
}, function() {
console.log('[BackgroundFetch] Event Received!')
this.updateAccounts()
BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA)
}.bind(this), function() {
console.log('[BackgroundFetch] FAILED')
}.bind(this))
}
public updateAccounts() {
let portal = new Portal()
let accounts = Database.current().findAll(Account)
accounts.forEach(async (account) => {
console.log('refresh account: ' + account.label)
await portal.refresh(account)
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment