Add the dependency
(iOS Only) Register BGTaskScheduler Identifiers
Info.plist file, add the following:Initialize Meeseeks
(JS Only) Service Worker Setup
service-worker.js:Get the "Meeseeks box"
BGTaskManager is essentially the MeeseeksBox. It is the global manager of all scheduled tasks. It is what you need to schedule a task (summon a MrMeeseeks).Make the request
Meeseeks fulfills the request
Frequently asked questions
How does Meeseeks store and persist tasks?
How does Meeseeks store and persist tasks?
What happens to tasks if my app is force-closed or the device reboots?
What happens to tasks if my app is force-closed or the device reboots?
Android:WorkManagerautomatically re-schedules tasks after a reboot if you configure it to do so.JVM: Tasks are re-scheduled withQuartzthe next time your application launches and re-initializes Meeseeks.Native (iOS): Tasks are re-scheduled withBGTaskSchedulerthe next time your application launches and re-initializes Meeseeks.JS (Web): If you usedSyncManagerorPeriodicSyncManager, the browser may continue to run tasks via theServiceWorkerin the background (user permissions and browser support permitting). Otherwise, tasks do not continue to run after the page is closed, but will be re-scheduled when the page is opened again.
How does Meeseeks handle concurrency across platforms?
How does Meeseeks handle concurrency across platforms?
Android: Concurrency is delegated toWorkManagerwhich manages parallel tasks according to OS constraints.JVM: Concurrency is similarly delegated toQuartz.Native (iOS): UsesBGTaskSchedulerfor periodic and one-time tasks. Tasks are canceled or updated locally in the DB, and on iOS 16+ can be canceled programmatically viacancelTaskRequestWithIdentifier.JS (Web): UsesServiceWorkersync/periodicsyncif available, otherwise in-memory timers.
What if I need to cancel or update a task after summoning it?
What if I need to cancel or update a task after summoning it?
MeeseeksBox.sendBackToBox(id) to cancel a task by its
MrMeeseeksId. This removes or cancels its scheduled job and updates the
database so it will not be run again. For updating a task’s data (such as
its schedule or priority), you will need to cancel the existing one and
summon a new Meeseeks with the updated Task.How do I track the status of a task?
How do I track the status of a task?
MeeseeksBox.getStatus(taskId)returns theTaskStatusof a single task, ornullif that task does not exist.MeeseeksBox.getAllTasks()returns a list ofScheduledTaskobjects, each containing the task’sMrMeeseeksId,TaskStatus, and other metadata (like run attempt count).MeeseeksBox.watchStatus(taskId)provides a reactive stream ofTaskStatuschanges.
How does Meeseeks handle different scheduling intervals?
How does Meeseeks handle different scheduling intervals?
TaskSchedule, which can be:TaskSchedule.OneTimeTaskSchedule.Periodic
PeriodicWorkRequests are used under the hood. On iOS, BGAppRefreshTaskRequest and BGProcessingTaskRequest are used under the hood.What are some examples of setting different scheduling intervals?
What are some examples of setting different scheduling intervals?
- One-Time Task
- Periodic Task
Do I need network connectivity for tasks to run?
Do I need network connectivity for tasks to run?
TaskPreconditions. For instance, if requiresNetwork = true, the task will not be run unless a network is available.What are some best practices for setting retry policies?
What are some best practices for setting retry policies?
- Use exponential backoff (
TaskRetryPolicy.ExponentialBackoff) for network-related tasks. This prevents tight loops and reduces server/battery load. - Limit max retries to avoid infinite attempts.
- Use fixed intervals (
TaskRetryPolicy.FixedInterval) if you’re sure the operation should repeat in consistent time blocks. - Log failed attempts thoroughly so you can identify repeated failures.
What if I need platform-specific logic in my background tasks?
What if I need platform-specific logic in my background tasks?
MeeseeksFactory that provides platform-specific code. For example, if you
need iOS-specific APIs, you could use expect/actual classes or call Swift
code from your iOS target. The library only orchestrates scheduling and
persistence. What the MrMeeseeks does inside execute() is up to you.How do TaskStatus state transitions work?
How do TaskStatus state transitions work?
TaskStatus to represent the lifecycle of tasks:- Pending: The task is scheduled but not currently running.
- Running: The task is actively executing.
- Finished: A terminal state indicating no further runs. It may be:
- Completed (successful)
- Cancelled (manually cancelled or platform removed it)
- Failed (permanently failed)
TaskResult.Success: Meeseeks sets the task status toFinished.Completed.TaskResult.RetryorTaskResult.Failure.Transient: Meeseeks reverts the task status toPendingso that it can be retried later (respecting any backoff or retry policy).TaskResult.Failure.Permanent: Meeseeks sets the task status toFinished.Failed, meaning no more attempts will be scheduled.
MeeseeksBox.sendBackToBox, it transitions to Finished.Cancelled. For tasks that fail with a transient error (e.g., network unavailable), the status simply goes back to Pending until the next run attempt.
