react-native-background-fetch – Periodic background tasks for React Native Apps

Background Fetch is a very simple plugin which will awaken an app in the background about every 15 minutes, providing a short period of background running-time. This plugin will execute your provided callbackFn whenever a background-fetch event occurs.

import BackgroundFetch from "react-native-background-fetch";

export default class App extends Component {
  componentDidMount() {
    // Configure it.
      minimumFetchInterval: 15,     // <-- minutes (15 is minimum allowed)
      // Android options
      forceAlarmManager: false,     // <-- Set true to bypass JobScheduler.
      stopOnTerminate: false,
      startOnBoot: true,
      requiredNetworkType: BackgroundFetch.NETWORK_TYPE_NONE, // Default
      requiresCharging: false,      // Default
      requiresDeviceIdle: false,    // Default
      requiresBatteryNotLow: false, // Default
      requiresStorageNotLow: false  // Default
    }, async (taskId) => {
      console.log("[js] Received background-fetch event: ", taskId);
      // 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
    }, (error) => {
      console.log("[js] RNBackgroundFetch failed to start");

From the source I see that on iOS it leverages the BackgroundTasks framework. Do note that the os might decide to throttle the rate the background-fetch so the define interval is only a minimum.


Scheduling Deploys with GitHub Actions

Leveraging GitHub Workflows’ Scheduled Events (read: cronjobs that run on GitHub) the folks at De Voorhoede let their static site automatically be rebuilt overnight. They do this because they have some external content, which doesn’t get committed into the repo, included on their site.

Static websites don’t update by themselves. In case of code changes (git push) and content changes (CMS publish event) a user triggers an update. But what if an external system (regularly) updates but can’t be configured to trigger an update? Enter cron jobs.

As their site is deployed onto Netlify, they let GitHub perform a curl request to Netlify’s Deploy Webhook, thus rebuilding and redeploying their site.

Their workflow file .github/workflows/nightly-build.yml is straightforward:

name: Scheduled build
  - cron: '30 3 * * *'
    runs-on: ubuntu-latest
    - name: Trigger our build webhook on Netlify
      run: curl -s -X POST "${TOKEN}"
        TOKEN: ${{ secrets.NETLIFY_CRON_BUILD_HOOK }}

The required NETLIFY_CRON_BUILD_HOOK is stored a GitHub Secret into the repo

Scheduling Netlify deploys with GitHub Actions →

💁‍♂️ Here’s a writeup I’ve done on deploying a static site onto Netlify, in case you’re looking for info on how to get started with Netlify.

Using ConsoleServiceProvider with Silex

use Knp\Provider\ConsoleServiceProvider;

$app->register(new ConsoleServiceProvider(), array(
	'' => 'ConsoleApp',
	'console.version' => '1.0.0',
	'console.project_directory' => __DIR__ . '/..'

Good writeup and code by Ken, a former student of mine.

Using ConsoleServiceProvider with Silex →

Want to start developing with Silex? Then check out my freely available course materials on the subject.