Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let BackgroundFetchHeadlessTask = async (event) => {
console.log('[BackgroundFetch HeadlessTask] start');
// Important: await asychronous tasks when using HeadlessJS.
/* DISABLED
let location = await BackgroundGeolocation.getCurrentPosition({persist: false, samples: 1});
console.log('- current position: ', location);
// Required: Signal to native code that your task is complete.
// If you don't do this, your app could be terminated and/or assigned
// battery-blame for consuming too much time in background.
*/
console.log('[BackgroundFetch HeadlessTask] finished');
BackgroundFetch.finish();
}
}, () => {
this.bgService.getPlugin().logger.ok('FETCH RECEIVED');
BackgroundFetch.finish();
}, (error) => {
console.warn('Fetch error: ', error);
export const task = async () => {
console.log('BACKGROUND TASK STARTING');
const { deployments, error: deploymentsError } = await api.deployments();
const usage = await api.usage();
if (deploymentsError || usage.error) {
console.log('BACKGROUND TASK ERROR', deploymentsError, usage.error);
BackgroundFetch.finish();
} else {
await saveDeployments(deployments);
await saveUsage(usage);
await notifyIfAppropriate(usage);
console.log('BACKGROUND TASK DONE');
BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA);
}
};
finish: function() {
BackgroundFetch.finish()
},