Offix Scheduler is the core component that delivers the offline queueing and storage in packages such as
offix-client. The scheduler can be used in an application directly to build offline workflows, or it can be as the foundation to build new packages and clients with offline functionality.
offix-client which provides many features out of the box,
offix-scheduler provides a lower level set of core functionalities which can be used to build offline experiences.
NetworkStatusinterface for defining when an app is and is not offline.
Executorinterface for defining the operations/behaviour to be scheduled. Example: A HTTP request, sending a message, a GraphQL request.
- Offline queue mechanism where all operations are scheduled and fulfilled in order.
OfflineQueueListenerfunctions that are called at various stages in the queue lifecycle. Can be used to extend the queue with additional behaviour.
- Offline storage mechanism for persisting operations in the queue and restoring them after application restarts.
See Offix-Client for a fully featured implementation that uses the Offix Scheduler.
This example shows how
offix-scheduler could be used to schedule HTTP Requests using the
fetch API found in most browsers.
Executor is a class or an object with an
execute method that will be called by the scheduler. This is the core operation/behaviour to be scheduled while offline. In this example we will define a
FetchExecutor class that can make requests using
execute method defines the business logic to be scheduled. In this example, we're scheduling HTTP
POST requests using the
execute accepts an
options object which can contain any properties needed to perform the operation. In this case
execute expects the options to have a
url which is where we will send the request and a
body which will be the body of the request.
This example is simplified as a realistic example would likely need to handle more options and also various error cases.
The example below shows how to initialize the
OffixScheduler with the
Executor we defined above.
To schedule an operation, call
execute on the scheduler and pass down any options needed by the