summaryrefslogtreecommitdiff
path: root/balancer.go
blob: 16418d55dfff5686226922135d85d0db7c19ce2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package roadrunner

//
//import (
//	"os/exec"
//	"sync"
//)
//
//// Swapper provides ability to perform hot-swap between 2 worker pools.
//type Swapper struct {
//	mu   sync.Mutex // protects pool hot swapping
//	pool *Pool      // pool to work for user commands
//}
//
//// Swap initiates underlying pool of workers and replaces old one.
//func (b *Swapper) Swap(cmd func() *exec.Cmd, factory Factory, cfg Config) error {
//	var (
//		err  error
//		prev *Pool
//		pool *Pool
//	)
//
//	prev = b.pool
//	if pool, err = NewPool(cmd, factory, cfg); err != nil {
//		return err
//	}
//
//	if prev != nil {
//		go func() {
//			prev.Close()
//		}()
//	}
//
//	b.mu.Lock()
//	b.pool = pool
//	b.mu.Unlock()
//
//	return nil
//}
//
//// Exec one task with given payload and context, returns result and context
//// or error. Must not be used once pool is being destroyed.
//func (b *Swapper) Exec(payload []byte, ctx interface{}) (resp []byte, rCtx []byte, err error) {
//	b.mu.Lock()
//	pool := b.pool
//	b.mu.Unlock()
//
//	if pool == nil {
//		panic("what")
//	}
//
//	return pool.Exec(payload, ctx)
//}
//
//// Workers return list of active workers.
//func (b *Swapper) Workers() []*Worker {
//	b.mu.Lock()
//	pool := b.pool
//	b.mu.Unlock()
//
//	return pool.Workers()
//}
//
//// Close closes underlying pool.
//func (b *Swapper) Close() {
//	b.mu.Lock()
//	defer b.mu.Unlock()
//
//	b.pool.Close()
//	b.pool = nil
//}