From 886129083b2af83cc7283ead30ebaec375c76904 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 29 Apr 2025 06:01:37 +0000 Subject: [PATCH 1/3] ci: update version to 0.5.8 [skip ci] --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e87a537..714b573 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-job-queue", "title": "React Native Job Queue", - "version": "0.5.5", + "version": "0.5.8", "description": "TODO", "react-native": "src/index.ts", "types": "lib/typescript/src", @@ -62,4 +62,4 @@ "typescript" ] } -} \ No newline at end of file +} From 95b6c5d12c911ce2a134abab5507a1a069f24a7c Mon Sep 17 00:00:00 2001 From: caglar09 Date: Tue, 29 Apr 2025 06:07:01 +0000 Subject: [PATCH 2/3] ci: merge release v0.5.8 to master --- dist/README.md | 243 + dist/lib/commonjs/Queue.js | 433 + dist/lib/commonjs/Queue.js.map | 1 + dist/lib/commonjs/Worker.js | 124 + dist/lib/commonjs/Worker.js.map | 1 + dist/lib/commonjs/hooks/useQueue.js | 92 + dist/lib/commonjs/hooks/useQueue.js.map | 1 + dist/lib/commonjs/index.js | 69 + dist/lib/commonjs/index.js.map | 1 + dist/lib/commonjs/models/Job.js | 22 + dist/lib/commonjs/models/Job.js.map | 1 + dist/lib/commonjs/models/JobStore.js | 6 + dist/lib/commonjs/models/JobStore.js.map | 1 + dist/lib/commonjs/utils/JobQueueMock.js | 84 + dist/lib/commonjs/utils/JobQueueMock.js.map | 1 + dist/lib/commonjs/utils/Uuid.js | 17 + dist/lib/commonjs/utils/Uuid.js.map | 1 + dist/lib/module/Queue.js | 426 + dist/lib/module/Queue.js.map | 1 + dist/lib/module/Worker.js | 117 + dist/lib/module/Worker.js.map | 1 + dist/lib/module/hooks/useQueue.js | 84 + dist/lib/module/hooks/useQueue.js.map | 1 + dist/lib/module/index.js | 8 + dist/lib/module/index.js.map | 1 + dist/lib/module/models/Job.js | 16 + dist/lib/module/models/Job.js.map | 1 + dist/lib/module/models/JobStore.js | 2 + dist/lib/module/models/JobStore.js.map | 1 + dist/lib/module/utils/JobQueueMock.js | 77 + dist/lib/module/utils/JobQueueMock.js.map | 1 + dist/lib/module/utils/Uuid.js | 10 + dist/lib/module/utils/Uuid.js.map | 1 + dist/lib/typescript/src/Queue.d.ts | 72 + dist/lib/typescript/src/Queue.d.ts.map | 1 + dist/lib/typescript/src/Worker.d.ts | 32 + dist/lib/typescript/src/Worker.d.ts.map | 1 + .../typescript/src/__tests__/Queue.test.d.ts | 4 + .../src/__tests__/Queue.test.d.ts.map | 1 + dist/lib/typescript/src/hooks/useQueue.d.ts | 12 + .../typescript/src/hooks/useQueue.d.ts.map | 1 + dist/lib/typescript/src/index.d.ts | 9 + dist/lib/typescript/src/index.d.ts.map | 1 + dist/lib/typescript/src/models/Job.d.ts | 36 + dist/lib/typescript/src/models/Job.d.ts.map | 1 + dist/lib/typescript/src/models/JobStore.d.ts | 16 + .../typescript/src/models/JobStore.d.ts.map | 1 + .../typescript/src/utils/JobQueueMock.d.ts | 20 + .../src/utils/JobQueueMock.d.ts.map | 1 + dist/lib/typescript/src/utils/Uuid.d.ts | 4 + dist/lib/typescript/src/utils/Uuid.d.ts.map | 1 + dist/package.json | 65 + release.zip | Bin 0 -> 65402 bytes yarn.lock | 8557 +++++++++++++++++ 54 files changed, 10682 insertions(+) create mode 100644 dist/README.md create mode 100644 dist/lib/commonjs/Queue.js create mode 100644 dist/lib/commonjs/Queue.js.map create mode 100644 dist/lib/commonjs/Worker.js create mode 100644 dist/lib/commonjs/Worker.js.map create mode 100644 dist/lib/commonjs/hooks/useQueue.js create mode 100644 dist/lib/commonjs/hooks/useQueue.js.map create mode 100644 dist/lib/commonjs/index.js create mode 100644 dist/lib/commonjs/index.js.map create mode 100644 dist/lib/commonjs/models/Job.js create mode 100644 dist/lib/commonjs/models/Job.js.map create mode 100644 dist/lib/commonjs/models/JobStore.js create mode 100644 dist/lib/commonjs/models/JobStore.js.map create mode 100644 dist/lib/commonjs/utils/JobQueueMock.js create mode 100644 dist/lib/commonjs/utils/JobQueueMock.js.map create mode 100644 dist/lib/commonjs/utils/Uuid.js create mode 100644 dist/lib/commonjs/utils/Uuid.js.map create mode 100644 dist/lib/module/Queue.js create mode 100644 dist/lib/module/Queue.js.map create mode 100644 dist/lib/module/Worker.js create mode 100644 dist/lib/module/Worker.js.map create mode 100644 dist/lib/module/hooks/useQueue.js create mode 100644 dist/lib/module/hooks/useQueue.js.map create mode 100644 dist/lib/module/index.js create mode 100644 dist/lib/module/index.js.map create mode 100644 dist/lib/module/models/Job.js create mode 100644 dist/lib/module/models/Job.js.map create mode 100644 dist/lib/module/models/JobStore.js create mode 100644 dist/lib/module/models/JobStore.js.map create mode 100644 dist/lib/module/utils/JobQueueMock.js create mode 100644 dist/lib/module/utils/JobQueueMock.js.map create mode 100644 dist/lib/module/utils/Uuid.js create mode 100644 dist/lib/module/utils/Uuid.js.map create mode 100644 dist/lib/typescript/src/Queue.d.ts create mode 100644 dist/lib/typescript/src/Queue.d.ts.map create mode 100644 dist/lib/typescript/src/Worker.d.ts create mode 100644 dist/lib/typescript/src/Worker.d.ts.map create mode 100644 dist/lib/typescript/src/__tests__/Queue.test.d.ts create mode 100644 dist/lib/typescript/src/__tests__/Queue.test.d.ts.map create mode 100644 dist/lib/typescript/src/hooks/useQueue.d.ts create mode 100644 dist/lib/typescript/src/hooks/useQueue.d.ts.map create mode 100644 dist/lib/typescript/src/index.d.ts create mode 100644 dist/lib/typescript/src/index.d.ts.map create mode 100644 dist/lib/typescript/src/models/Job.d.ts create mode 100644 dist/lib/typescript/src/models/Job.d.ts.map create mode 100644 dist/lib/typescript/src/models/JobStore.d.ts create mode 100644 dist/lib/typescript/src/models/JobStore.d.ts.map create mode 100644 dist/lib/typescript/src/utils/JobQueueMock.d.ts create mode 100644 dist/lib/typescript/src/utils/JobQueueMock.d.ts.map create mode 100644 dist/lib/typescript/src/utils/Uuid.d.ts create mode 100644 dist/lib/typescript/src/utils/Uuid.d.ts.map create mode 100644 dist/package.json create mode 100644 release.zip create mode 100644 yarn.lock diff --git a/dist/README.md b/dist/README.md new file mode 100644 index 0000000..fa8c093 --- /dev/null +++ b/dist/README.md @@ -0,0 +1,243 @@ +# React Native Job Queue + +This library is inspired by [react-native-queue](https://github.com/billmalarky/react-native-queue) which seems to be unmaintained. +Instead of using realm, this library provides an own sqlite based native implementation. + +Since react-native struggles with using `use_frameworks!` in pod files i wasn't able to use https://github.com/stephencelis/SQLite.swift and had to implement the native ios part guided by https://www.raywenderlich.com/385-sqlite-with-swift-tutorial-getting-started . If react-native starts to support `use_frameworks!` or you are able to make it work, feel free to do a PR. +On Android i used Androids Room-Persitence-Library. + +You can find API-Reference [here](https://simonerm.github.io/react-native-job-queue/docs/) + +## Getting started (RN>=0.60) + +`$ npm install react-native-job-queue --save` + +### Install Pods + +`$ cd ios && pod install` + +A persistent, cross-platform job queue for React Native applications, enabling reliable background task processing on both Android and iOS. + +## Features + +- **Cross-Platform**: Seamlessly works on Android and iOS using native implementations. +- **Persistent Storage**: Jobs are saved to native device storage (SQLite on iOS, Room on Android) and persist across app restarts. +- **Background Processing**: Define and execute tasks in the background, independent of the UI thread. +- **Worker System**: Register custom worker functions to handle different types of jobs. +- **Concurrency Control**: Configure the maximum number of jobs to run concurrently, both globally and per worker. +- **Job Lifecycle Management**: Full control over jobs: add, start, stop, cancel, requeue, and remove. +- **Retry Logic**: Automatically retry failed jobs with a configurable number of attempts. +- **Timeouts**: Set timeouts for jobs to prevent them from running indefinitely. +- **Prioritization**: Assign priorities to jobs to influence execution order. +- **Event System**: Subscribe to events for job lifecycle updates (added, started, succeeded, failed, completed). +- **React Hook (`useQueue`)**: Easily monitor and display queue status within your React components. + +## Architecture Overview + +The library consists of three main parts: + +1. **JavaScript/TypeScript Layer**: + Provides the public API (`Queue`, `Worker`, `useQueue`) for interacting with the job queue from your React Native application. It manages workers, job creation, and communication with the native layer. + +2. **Native Android Implementation (Java)**: + A native module using the Room Persistence Library to store and manage jobs in an SQLite database. It handles job fetching, updating, and deletion on Android devices. + +3. **Native iOS Implementation (Swift/Objective-C)**: + A native module using SQLite directly to provide job persistence and management capabilities on iOS devices. + +The JavaScript layer communicates with the appropriate native module via the React Native bridge to ensure jobs are stored reliably and processed efficiently in the background. + +## Installation + +```bash +# Using npm +npm install --save + +# Using yarn +yarn add + +# Link native modules +react-native link + +# Install pods for iOS +cd ios && pod install +``` + +> **Note**: Replace `` with the actual name of your package once published. + +## Basic Usage + +### 1. Configure the Queue (Optional) + +```typescript +import queue from ''; + +queue.configure({ + onQueueFinish: (executedJobs) => { + console.log('Queue finished processing:', executedJobs); + }, + updateInterval: 15, + concurrency: 5, +}); +``` + +### 2. Define a Worker + +```typescript +import { Worker } from ''; + +interface MyJobPayload { + userId: string; + data: any; + delay?: number; +} + +const myWorker = new Worker( + 'my-task-worker', + async (payload, jobId) => { + console.log(`Running job ${jobId} for user ${payload.userId}`); + await new Promise((resolve) => setTimeout(resolve, payload.delay || 1000)); + console.log(`Job ${jobId} completed successfully.`); + }, + { + concurrency: 3, + onStart: (job) => console.log(`Job ${job.id} started.`), + onSuccess: (job) => console.log(`Job ${job.id} succeeded.`), + onFailure: (job, error) => console.log(`Job ${job.id} failed:`, error.message), + onCompletion: (job) => console.log(`Job ${job.id} completed.`), + } +); + +queue.addWorker(myWorker); +``` + +### 3. Add a Job + +```typescript +const jobPayload: MyJobPayload = { + userId: 'user-123', + data: { message: 'Process this data' }, + delay: 2000, +}; + +const jobId = queue.addJob('my-task-worker', jobPayload, { + attempts: 3, + timeout: 10000, + priority: 1, +}); + +console.log(`Added job with ID: ${jobId}`); + +// queue.start(); +``` + +### 4. Monitor Queue State (using `useQueue` hook) + +```typescript +import React from 'react'; +import { View, Text, Button } from 'react-native'; +import { useQueue } from ''; + +function QueueStatusDisplay() { + const { queuedCount, activeCount, failedCount, completedCount, activeJobs, lastCompletedJobs, refreshJobs } = + useQueue(); + + return ( + + Queued: {queuedCount} + Active: {activeCount} + Failed: {failedCount} + Completed: {completedCount} +