Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}, async () => {
console.log('- BackgroundFetch start');
let location = await BackgroundGeolocation.getCurrentPosition({persist: true, samples:1, extras: {'context': 'background-fetch-position'}});
console.log('- BackgroundFetch current position: ', location) // <-- don't see this
BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA);
}, (error) => {
console.log('[js] RNBackgroundFetch failed to start')
() => {
console.log('[js] Received background-fetch event');
// Required: Signal completion of your task to native code
// If you fail to do this, the OS can terminate your app
// or assign battery-blame for consuming too much background-time
BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA);
},
error => {
}
await this.api.checkCafeMessages()
await delay(ms / 2)
if (cancelled) { // cancelled by event, so abort sequence
foregroundEvent.remove() // remove our event listener
break cancelSequence
}
// enter stopping sequence
foregroundEvent.remove() // remove our event listener
TextileEvents.stopNodeAfterDelayFinishing()
await this.stopNode() // stop the node
cancelled = true // be sure to exit the loop
}
await BackgroundTimer.stop()
await BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA)
}
}
await API.cafes.checkMessages()
await delay(ms / 2)
if (cancelled) { // cancelled by event, so abort sequence
foregroundEvent.remove() // remove our event listener
break
}
// enter stopping sequence
foregroundEvent.remove() // remove our event listener
TextileEvents.stopNodeAfterDelayFinishing()
await this.stopNode() // stop the node
TextileEvents.stopNodeAfterDelayComplete()
cancelled = true // be sure to exit the loop
}
} finally {
// TODO: this might be better in a client provided callback
await BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA)
// Tells iOS that we are done with our background task so it's okay to suspend us
await BackgroundTimer.stop()
}
}
}
function finish() {
// Send an ackknowledge when we are done - required only by iOS
if (Platform.OS === 'ios')
BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA)
}
function * backgroundTaskRace () {
// This race cancels whichever effect looses the race, so a foreground event will cancel stopping the node
//
// Using the race effect, if we get a foreground event while we're waiting
// to stop the node, cancel the stop and let it keep running
yield call(BackgroundTimer.start)
yield race({
delayAndStopNode: call(stopNodeAfterDelay, 20000),
foregroundEvent: take(
(action: RootAction) =>
action.type === getType(TextileNodeActions.appStateChange) && action.payload.newState === 'active'
)
})
yield all([
call(BackgroundTimer.stop),
call(BackgroundFetch.finish, BackgroundFetch.FETCH_RESULT_NEW_DATA)
])
}
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);
}
};
async () => {
await pushTracking('backgroundFetch', 'started')
await clearAndDownloadIssue()
await pushTracking('backgroundFetch', 'ended')
BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA)
},
error => {