{"id":1992,"url":"https://github.com/BrettRToomey/Jobs","last_synced_at":"2025-07-31T12:33:26.670Z","repository":{"id":80713930,"uuid":"73116864","full_name":"BrettRToomey/Jobs","owner":"BrettRToomey","description":"A job system for Swift backends.","archived":false,"fork":false,"pushed_at":"2020-07-19T18:33:19.000Z","size":69,"stargazers_count":293,"open_issues_count":10,"forks_count":22,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-08-15T00:20:02.221Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrettRToomey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-11-07T20:14:53.000Z","updated_at":"2024-06-28T11:30:17.000Z","dependencies_parsed_at":"2023-03-12T11:58:23.602Z","dependency_job_id":null,"html_url":"https://github.com/BrettRToomey/Jobs","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrettRToomey%2FJobs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrettRToomey%2FJobs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrettRToomey%2FJobs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrettRToomey%2FJobs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrettRToomey","download_url":"https://codeload.github.com/BrettRToomey/Jobs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228248428,"owners_count":17891447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:00.702Z","updated_at":"2024-12-05T06:31:20.449Z","avatar_url":"https://github.com/BrettRToomey.png","language":"Swift","funding_links":[],"categories":["Server"],"sub_categories":["Keychain","Other free courses"],"readme":"# Jobs\n[![Language](https://img.shields.io/badge/Swift-4-brightgreen.svg)](http://swift.org) ![Build Status](https://travis-ci.org/BrettRToomey/Jobs.svg?branch=master)\n[![codecov](https://codecov.io/gh/BrettRToomey/Jobs/branch/master/graph/badge.svg)](https://codecov.io/gh/BrettRToomey/Jobs)\n[![codebeat badge](https://codebeat.co/badges/1a9e0ad5-33d5-4bbc-a229-1691250f69d3)](https://codebeat.co/projects/github-com-brettrtoomey-jobs)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/BrettRToomey/Jobs/master/LICENSE.md)\n\nA minimalistic job system in Swift, for Swift\n\n##### Table of Contents\n* [Getting started](#getting-started-)\n* [Intervals](#intervals-)\n  * [Syntax candy](#syntax-candy-)\n* [Starting a job](#starting-a-job-)\n* [Stopping a job](#stopping-a-job-)\n* [Error handling](#error-handling-)\n  * [Retry on failure](#retry-on-failure-)\n\n## Integration\nUpdate your `Package.swift` file.\n```swift\n.package(url: \"https://github.com/BrettRToomey/Jobs.git\", from: \"1.1.1\")\n```\n\n## Getting started 🚀\nCreating a new `Job` is as simple as:\n```swift\nJobs.add(interval: .seconds(4)) {\n    print(\"👋 I'm printed every 4 seconds!\")\n}\n```\n\n## Intervals ⏲\nThe `Duration` enumeration currently supports `.seconds`, `hours`, `.days` and `.weeks`.\n```swift\nJobs.add(interval: .days(5)) {\n    print(\"See you every 5 days.\")\n}\n```\n#### Syntax candy 🍭\nIt's possible to create a `Duration` from an `Int` and a `Double`.\n```swift\n10.seconds // `Duration.seconds(10)`\n4.hours // `Duration.hours(4)`\n2.days // `Duration.days(2)`\n3.weeks // `Duration.weeks(3)`\n```\n\n## Starting a job 🎬\nBy default, `Job`s are started automatically, but if you wish to start one yourself, even at a later point in time, just do the following:\n```swift\nlet job = Jobs.add(interval: 2.seconds, autoStart: false) {\n    print(\"I wasn't started right away.\")\n}\n//...\njob.start()\n```\n\n## Stopping a job ✋\nGiving up has never been so easy!\n```swift\njob.stop()\n```\n\n## One-off jobs\nIf you just want to asynchronously run a job, but not repeat it you can use the `oneoff` functions.\n```swift\nJobs.oneoff {\n    print(\"Sadly, I'm not a phoenix.\")            \n}\n```\n\nHow about waiting a little?\n```swift\nJobs.oneoff(delay: 10.seconds) {\n    print(\"I was delayed by 10 seconds.\")\n}\n```\n\n## Error handling ❌\nSometimes jobs can fail, that's okay, we have you covered.\n```swift\nJobs.add(\n    interval: 10.seconds,\n    action: {\n        throw Error.someError\n    },\n    onError: { error in\n        print(\"caught an error: \\(error)\")\n        return RecoverStrategy.default\n    }\n)\n```\n\n#### Retry on failure ⭕️\nBy default, jobs will be attempted again after a five second delay. If you wish to override this behavior you must first implement an `onError` handler and return one of the following `RecoveryStrategy` cases.\n```swift\n.none //do not retry\n.default //retry after 5 seconds\n.retry(after: Duration) //retry after specified duration\n```\nHere's a small sample:\n```swift\nenum Error: Swift.Error {\n  case recoverable\n  case abort\n}\n\nJobs.add(\n    interval: 1.days,\n    action: {\n        //...\n    },\n    onError: { error in\n        switch error {\n        //we cannot recover from this\n        case .abort:\n            //do not retry\n            return .none\n\n        //we can recover from this\n        case .recoverable:\n            //... recovery code\n\n            //try again in 15 seconds\n            return .retry(after: 15.seconds)\n        }\n    }\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBrettRToomey%2FJobs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBrettRToomey%2FJobs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBrettRToomey%2FJobs/lists"}