Skip to content

Commit

Permalink
Merge pull request #40 from 0xTim/master
Browse files Browse the repository at this point in the history
Update for Swift 4
  • Loading branch information
BrettRToomey authored Oct 14, 2017
2 parents 838827f + 4a10ce5 commit 2051cc4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.build
/Packages
/*.xcodeproj
DerivedData/
31 changes: 26 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
os:
- linux
- osx
- linux
- osx
language: generic
sudo: required
dist: trusty
osx_image: xcode8

osx_image: xcode9
before_install:
- if [ $TRAVIS_OS_NAME == "osx" ]; then
HOMEBREW_NO_AUTO_UPDATE=1 brew install vapor/tap/vapor;
else
eval "$(curl -sL https://apt.vapor.sh)";
sudo apt-get install vapor;
sudo chmod -R a+rx /usr/;
fi

script:
- eval "$(curl -sL https://swift.vapor.sh/ci)"
- eval "$(curl -sL https://swift.vapor.sh/codecov)"
- swift build
- swift build -c release
- swift test
- if [ $TRAVIS_OS_NAME != "osx" ]; then
sudo apt-get remove vapor;
sudo apt-get install swift=3.1.1;
swift build;
swift build -c release;
swift test;
fi

after_success:
- eval "$(curl -sL https://raw.githubusercontent.com/vapor-community/swift/master/codecov)"
14 changes: 14 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-tools-version:4.0

import PackageDescription

let package = Package(
name: "Jobs",
products: [
.library(name: "Jobs", targets: ["Jobs"]),
],
targets: [
.target(name: "Jobs", path: "Sources"),
.testTarget(name: "JobsTests", dependencies: ["Jobs"]),
]
)
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Jobs
[![Language](https://img.shields.io/badge/Swift-3-brightgreen.svg)](http://swift.org) ![Build Status](https://travis-ci.org/BrettRToomey/Jobs.svg?branch=master)
[![Language](https://img.shields.io/badge/Swift-4-brightgreen.svg)](http://swift.org) ![Build Status](https://travis-ci.org/BrettRToomey/Jobs.svg?branch=master)
[![codecov](https://codecov.io/gh/BrettRToomey/Jobs/branch/master/graph/badge.svg)](https://codecov.io/gh/BrettRToomey/Jobs)
[![codebeat badge](https://codebeat.co/badges/1a9e0ad5-33d5-4bbc-a229-1691250f69d3)](https://codebeat.co/projects/github-com-brettrtoomey-jobs)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/BrettRToomey/Jobs/master/LICENSE.md)
Expand All @@ -18,7 +18,7 @@ A minimalistic job system in Swift, for Swift
## Integration
Update your `Package.swift` file.
```swift
.Package(url: "https://github.com/BrettRToomey/Jobs.git", majorVersion: 1)
.package(url: "https://github.com/BrettRToomey/Jobs.git", from: "1.1.1")
```

## Getting started 🚀
Expand Down Expand Up @@ -61,7 +61,7 @@ Giving up has never been so easy!
job.stop()
```

## One-off jobs
## One-off jobs
If you just want to asynchronously run a job, but not repeat it you can use the `oneoff` functions.
```swift
Jobs.oneoff {
Expand All @@ -83,7 +83,7 @@ Jobs.add(
interval: 10.seconds,
action: {
throw Error.someError
},
},
onError: { error in
print("caught an error: \(error)")
return RecoverStrategy.default
Expand All @@ -99,7 +99,7 @@ By default, jobs will be attempted again after a five second delay. If you wish
.retry(after: Duration) //retry after specified duration
```
Here's a small sample:
```swift
```swift
enum Error: Swift.Error {
case recoverable
case abort
Expand All @@ -109,7 +109,7 @@ Jobs.add(
interval: 1.days,
action: {
//...
},
},
onError: { error in
switch error {
//we cannot recover from this
Expand Down
6 changes: 5 additions & 1 deletion Sources/Shell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public func shell(path launchPath: String, args arguments: [String]) throws -> S

if result.characters.count > 0 {
let lastIndex = result.index(before: result.endIndex)
return result[result.startIndex ..< lastIndex]
#if swift(>=4)
return String(result[result.startIndex ..< lastIndex])
#else
return result[result.startIndex ..< lastIndex]
#endif
}

return result
Expand Down

0 comments on commit 2051cc4

Please sign in to comment.