Set up and summon your first Meeseeks.
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
MeeseeksBox
is the global manager of all scheduled tasks. It is what you need to summon a MrMeeseeks
.Define a task
Summon a Meeseeks
MrMeeseeks
in the
Advanced Docs.How does Meeseeks store and persist tasks?
What happens to tasks if my app is force-closed or the device reboots?
Android
: WorkManager
automatically
re-schedules tasks after a reboot if you configure it to do so.JVM
: Tasks are re-scheduled with Quartz
the next time your application launches and re-initializes Meeseeks.Native (iOS)
: Tasks are re-scheduled with BGTaskScheduler
the next time your application launches and re-initializes Meeseeks.JS (Web)
: If you used SyncManager
or PeriodicSyncManager
, the browser may continue to run tasks via the ServiceWorker
in 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?
Android
: Concurrency is delegated to WorkManager
which manages parallel
tasks according to OS constraints.JVM
: Concurrency is similarly delegated to Quartz
.Native (iOS)
: Uses BGTaskScheduler
for periodic and one-time tasks. Tasks are canceled or updated locally in the DB, and on iOS 16+ can be canceled programmatically via cancelTaskRequestWithIdentifier
.JS (Web)
: Uses ServiceWorker
sync
/periodicsync
if available, otherwise in-memory timers.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?
MeeseeksBox.getStatus(taskId)
returns the TaskStatus
of a single task, or null
if that task does not exist.MeeseeksBox.getAllTasks()
returns a list of ScheduledTask
objects, each containing the task’s MrMeeseeksId
, TaskStatus
, and other metadata (like run attempt count).MeeseeksBox.watchStatus(taskId)
provides a reactive stream of TaskStatus
changes.How does Meeseeks handle different scheduling intervals?
TaskSchedule
, which can be:TaskSchedule.OneTime
TaskSchedule.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?
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?
TaskRetryPolicy.ExponentialBackoff
) for
network-related tasks. This prevents tight loops and reduces server/battery
load.TaskRetryPolicy.FixedInterval
) if you’re sure the operation should repeat in consistent time blocks.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?
TaskStatus
to represent the lifecycle of tasks:TaskResult.Success
: Meeseeks sets the task status to Finished.Completed
.TaskResult.Retry
or TaskResult.Failure.Transient
: Meeseeks reverts the task status to Pending
so that it can be retried later (respecting any backoff or retry policy).TaskResult.Failure.Permanent
: Meeseeks sets the task status to Finished.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.