Skip to content

Commit

Permalink
Allow disabling worker timeouts
Browse files Browse the repository at this point in the history
Closes #24
  • Loading branch information
kylef committed Feb 12, 2016
1 parent 69880b9 commit 738d85a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ hasn't responded to the master process.
$ ./.build/release/HelloWorld --timeout 30
```

You can set the timeout to `0` to disable worker timeout handling.

### FAQ

#### What platforms does Curassow support?
Expand Down
11 changes: 10 additions & 1 deletion Sources/Arbiter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ class Arbiter<Worker : WorkerType> {

/// Sleep, waiting for stuff to happen on our signal pipe
func sleep() {
let timeout = timeval(tv_sec: self.timeout, tv_usec: 0)
let timeout: timeval

if self.timeout > 0 {
timeout = timeval(tv_sec: self.timeout, tv_usec: 0)
} else {
timeout = timeval(tv_sec: 30, tv_usec: 0)
}

let (read, _, _) = select([signalHandler.pipe[0]], [], [], timeout: timeout)

if !read.isEmpty {
Expand Down Expand Up @@ -199,6 +206,8 @@ class Arbiter<Worker : WorkerType> {

// Murder workers that have timed out
func murderWorkers() {
if timeout == 0 { return }

var currentTime = timeval()
gettimeofday(&currentTime, nil)

Expand Down
9 changes: 8 additions & 1 deletion Sources/SyncronousWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ final class SyncronousWorker : WorkerType {
}

func wait() -> [Socket] {
let timeout = timeval(tv_sec: self.timeout, tv_usec: 0)
let timeout: timeval

if self.timeout > 0 {
timeout = timeval(tv_sec: self.timeout, tv_usec: 0)
} else {
timeout = timeval(tv_sec: 120, tv_usec: 0)
}

let (read, _, _) = select(listeners + [sharedHandler!.pipe[0]], [], [], timeout: timeout)
return read
}
Expand Down

0 comments on commit 738d85a

Please sign in to comment.