Skip to content

Commit 84d641e

Browse files
feat: Initial commit of PollingEngine KMP library and sample app
This commit introduces the PollingEngine, a Kotlin Multiplatform (KMP) library designed for robust polling with configurable exponential backoff and jitter. **Key components:** * **`pollingengine` module:** * Core polling logic (`PollingEngine.kt`) with support for coroutine cancellation, customizable fetch/success/retry strategies, and observability hooks. * Flexible backoff configuration (`BackoffPolicy.kt`, `BackoffPolicies.kt`) including initial delay, max delay, multiplier, jitter, max attempts, and overall/per-attempt timeouts. * Configuration builder (`PollingConfigBuilder.kt`) for fluent setup. * Internal models for polling results (`PollingResult.kt`) and errors (`Error.kt`). * Basic tests for `BackoffPolicy` and rogue `CancellationException` handling. * Android (AAR) and iOS (XCFramework via CocoaPods) targets. * Gradle setup for publishing, Dokka documentation, Detekt, and ktlint. * **`composeApp` module:** * A sample Compose Multiplatform application demonstrating usage of the `pollingengine` library. * Includes a simple UI with a button to trigger a polling demo (`PollingSamples.kt`). * Basic Android and iOS app structure. * **Project structure:** * Gradle setup for KMP, Android application/library, Compose Multiplatform, and iOS. * CI workflows for build, static checks (Detekt, ktlint, Dokka, API check), CodeQL analysis, and release publishing to Sonatype/GitHub Releases. * Documentation for CI setup, contribution guidelines, and README. * Community files (LICENSE, CODE\_OF\_CONDUCT, SECURITY.md). * Helper script (`fix-ios-simulator.sh`) for resolving common iOS Simulator issues. **Functionality:** * The polling engine (`PollingEngine.pollUntil`) executes a provided fetch operation repeatedly until a success condition is met or limits (attempts, timeout) are reached. * Supports exponential backoff with jitter to manage retry intervals efficiently. * Handles errors and cancellation gracefully, with hooks for logging and metrics. * Allows consumers to define custom logic for fetching data, determining success, and deciding when to retry errors.
0 parents  commit 84d641e

72 files changed

Lines changed: 3134 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gradle"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
open-pull-requests-limit: 5
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
12+
open-pull-requests-limit: 5

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main, master ]
7+
8+
jobs:
9+
build:
10+
name: Build and Static Checks
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-latest]
14+
runs-on: ${{ matrix.os }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: 17
22+
- name: Cache Gradle
23+
uses: actions/cache@v4
24+
with:
25+
path: |
26+
~/.gradle/caches
27+
~/.gradle/wrapper
28+
~/.konan
29+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
30+
restore-keys: |
31+
${{ runner.os }}-gradle-
32+
- name: Grant execute permission for gradlew
33+
run: chmod +x gradlew
34+
- name: Build
35+
run: ./gradlew build --stacktrace
36+
- name: Detekt
37+
run: ./gradlew detekt --stacktrace
38+
- name: ktlint
39+
run: ./gradlew ktlintCheck --stacktrace
40+
- name: Dokka HTML
41+
run: ./gradlew :pollingengine:dokkaHtml --stacktrace
42+
- name: API check (if baseline present)
43+
run: if [ -d api ]; then ./gradlew :pollingengine:apiCheck --stacktrace; else echo "Skipping apiCheck (no baseline)"; fi

.github/workflows/codeql.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CodeQL
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
schedule:
9+
- cron: '0 3 * * 1'
10+
11+
jobs:
12+
analyze-kotlin:
13+
name: Analyze (Java/Kotlin)
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: github/codeql-action/init@v3
22+
with:
23+
languages: 'java-kotlin'
24+
- uses: github/codeql-action/autobuild@v3
25+
- uses: github/codeql-action/analyze@v3
26+
27+
analyze-swift:
28+
name: Analyze (Swift)
29+
runs-on: macos-latest
30+
permissions:
31+
actions: read
32+
contents: read
33+
security-events: write
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: github/codeql-action/init@v3
37+
with:
38+
languages: 'swift'
39+
- uses: github/codeql-action/autobuild@v3
40+
- uses: github/codeql-action/analyze@v3

.github/workflows/docs.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Set up JDK 17
16+
uses: actions/setup-java@v4
17+
with:
18+
distribution: temurin
19+
java-version: 17
20+
- name: Cache Gradle
21+
uses: actions/cache@v4
22+
with:
23+
path: |
24+
~/.gradle/caches
25+
~/.gradle/wrapper
26+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
27+
restore-keys: |
28+
${{ runner.os }}-gradle-
29+
- name: Generate Dokka HTML
30+
run: ./gradlew :pollingengine:dokkaHtml --stacktrace
31+
- name: Publish to GitHub Pages (gh-pages)
32+
uses: peaceiris/actions-gh-pages@v4
33+
with:
34+
github_token: ${{ secrets.GITHUB_TOKEN }}
35+
publish_dir: pollingengine/build/dokka/html
36+
publish_branch: gh-pages
37+
force_orphan: true

.github/workflows/release.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish:
10+
runs-on: macos-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Set up JDK 17
16+
uses: actions/setup-java@v4
17+
with:
18+
distribution: temurin
19+
java-version: 17
20+
- name: Cache Gradle
21+
uses: actions/cache@v4
22+
with:
23+
path: |
24+
~/.gradle/caches
25+
~/.gradle/wrapper
26+
~/.konan
27+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
28+
restore-keys: |
29+
${{ runner.os }}-gradle-
30+
- name: Grant execute permission for gradlew
31+
run: chmod +x gradlew
32+
- name: Build library artifacts
33+
run: ./gradlew :pollingengine:build :pollingengine:assembleReleaseXCFramework --stacktrace
34+
- name: Generate docs
35+
run: ./gradlew :pollingengine:dokkaHtml --stacktrace
36+
- name: Publish to Sonatype (if secrets present)
37+
if: ${{ secrets.OSSRH_USERNAME != '' && secrets.OSSRH_PASSWORD != '' && secrets.SIGNING_KEY != '' && secrets.SIGNING_PASSWORD != '' }}
38+
env:
39+
ossrhUsername: ${{ secrets.OSSRH_USERNAME }}
40+
ossrhPassword: ${{ secrets.OSSRH_PASSWORD }}
41+
signing.key: ${{ secrets.SIGNING_KEY }}
42+
signing.password: ${{ secrets.SIGNING_PASSWORD }}
43+
run: ./gradlew :pollingengine:publishToSonatype closeAndReleaseSonatypeStagingRepository --stacktrace
44+
- name: Zip XCFramework
45+
run: |
46+
cd pollingengine/build/XCFrameworks/release
47+
zip -r PollingEngine.xcframework.zip PollingEngine.xcframework
48+
- name: Zip Dokka HTML
49+
run: |
50+
cd pollingengine/build/dokka/html
51+
zip -r ../../dokka-html.zip .
52+
- name: Attach artifacts to GitHub Release
53+
uses: softprops/action-gh-release@v2
54+
with:
55+
files: |
56+
pollingengine/build/XCFrameworks/release/PollingEngine.xcframework.zip
57+
pollingengine/build/dokka/dokka-html.zip
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
- name: Publish docs to GitHub Pages (gh-pages)
61+
uses: peaceiris/actions-gh-pages@v4
62+
with:
63+
github_token: ${{ secrets.GITHUB_TOKEN }}
64+
publish_dir: pollingengine/build/dokka/html
65+
publish_branch: gh-pages
66+
force_orphan: true

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on Keep a Changelog and this project adheres to Semantic Versioning (SemVer).
6+
7+
## [Unreleased]
8+
- CI workflows (build, static checks) and CodeQL added.
9+
- Release workflow scaffolding (tag `v*`) with conditional publishing to Sonatype.
10+
- Binary Compatibility Validator plugin applied (baseline pending).
11+
- Documentation updates and community files (LICENSE, CODE_OF_CONDUCT, CONTRIBUTING, SECURITY).
12+
13+
## [0.1.0] - 2025-09-05
14+
Initial extraction of PollingEngine as a KMP library.
15+
- Kotlin Multiplatform library module `:pollingengine` with Android and iOS (XCFramework) targets.
16+
- Polling engine with backoff, jitter, hooks, and metrics interfaces.
17+
- Sample `composeApp` depending on the library.

CODE_OF_CONDUCT.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Code of Conduct
2+
3+
We follow the Contributor Covenant Code of Conduct.
4+
5+
- Be respectful and welcoming.
6+
- Use inclusive language.
7+
- Accept constructive criticism.
8+
- Focus on what is best for the community.
9+
10+
For the full text, see: https://www.contributor-covenant.org/version/2/1/code_of_conduct/
11+
12+
If you witness or experience unacceptable behavior, please report it to the maintainers via GitHub Issues or by email (see SECURITY.md for reporting).

CONTRIBUTING.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Contributing to PollingEngine
2+
3+
Thanks for your interest in contributing! Please follow these guidelines to help us keep the project healthy and maintainable.
4+
5+
## Development setup
6+
- Use the latest Android Studio or IntelliJ IDEA with Kotlin Multiplatform support.
7+
- JDK 17 is required for builds and CI.
8+
- Run `./gradlew build` to verify.
9+
10+
## Code style and static checks
11+
- Ktlint and Detekt are enabled. Run:
12+
- `./gradlew ktlintFormat ktlintCheck`
13+
- `./gradlew detekt`
14+
- Keep changes small and focused; add tests where possible.
15+
16+
## Commit messages and PRs
17+
- Use clear, descriptive commit messages.
18+
- Open PRs against `main` and ensure CI passes.
19+
- Link related issues and describe the rationale for changes.
20+
21+
## API stability
22+
- The library uses semantic versioning (MAJOR.MINOR.PATCH).
23+
- Public API changes should be intentional; Binary Compatibility Validator (apiCheck) runs in CI.
24+
25+
## Reporting issues
26+
- Provide reproduction steps, expected vs actual behavior, and environment details.
27+
28+
## License
29+
By contributing, you agree that your contributions will be licensed under the Apache-2.0 License.

LICENSE

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Apache License
2+
Version 2.0, January 2004
3+
http://www.apache.org/licenses/
4+
5+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6+
7+
1. Definitions.
8+
9+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10+
11+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12+
13+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14+
15+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16+
17+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18+
19+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20+
21+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22+
23+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24+
25+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26+
27+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28+
29+
2. Grant of Copyright License.
30+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
31+
32+
3. Grant of Patent License.
33+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34+
35+
4. Redistribution.
36+
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
37+
38+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
39+
40+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
41+
42+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
43+
44+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
45+
46+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
47+
48+
5. Submission of Contributions.
49+
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
50+
51+
6. Trademarks.
52+
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
53+
54+
7. Disclaimer of Warranty.
55+
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
56+
57+
8. Limitation of Liability.
58+
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
59+
60+
9. Accepting Warranty or Additional Liability.
61+
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
62+
63+
END OF TERMS AND CONDITIONS

0 commit comments

Comments
 (0)