Reviewers: mp+169234_code.launchpad.net,
Message: Please take a look.
Description: resumer: periodically resume transaction
The resumer is a periodically worker which is resuming pending transactions in state each minute.
https://code.launchpad.net/~themue/juju-core/026-transaction-resumer/+merge/169234
(do not edit description out of merge proposal)
Please review this at https://codereview.appspot.com/10266043/
Affected files: A [revision details] M state/state.go A worker/resumer/resumer.go A worker/resumer/resumer_test.go
Index: [revision details] === added file '[revision details]' --- [revision details] 2012-01-01 00:00:00 +0000 +++ [revision details] 2012-01-01 00:00:00 +0000 @@ -0,0 +1,2 @@ +Old revision: tarmac-20130613115315-e58eqa122kc07o1a +New revision: <email address hidden>
Index: state/state.go === modified file 'state/state.go' --- state/state.go 2013-06-12 02:45:22 +0000 +++ state/state.go 2013-06-13 15:29:49 +0000 @@ -1123,6 +1123,11 @@ return nil }
+// ResumeTransactions resumes all pending transactions. +func (st *State) ResumeTransactions() error { + return st.runner.ResumeAll() +} + var tagPrefix = map[byte]string{ 'm': "machine-", 's': "service-",
Index: worker/resumer/resumer.go === added file 'worker/resumer/resumer.go' --- worker/resumer/resumer.go 1970-01-01 00:00:00 +0000 +++ worker/resumer/resumer.go 2013-06-13 15:29:49 +0000 @@ -0,0 +1,62 @@ +// Copyright 2012, 2013 Canonical Ltd. +// Licensed under the AGPLv3, see LICENCE file for details. + +package resumer + +import ( + "fmt" + "launchpad.net/juju-core/log" + "launchpad.net/juju-core/state" + "launchpad.net/tomb" + "time" +) + +// interval sets how often the resuming is called. +const interval = time.Minute + +// Resumer is responsible for a periodical resuming of pending transactions. +type Resumer struct { + tomb tomb.Tomb + st *state.State +} + +// NewResumer ... +func NewResumer(st *state.State) *Resumer { + rr := &Resumer{st: st} + go func() { + defer rr.tomb.Done() + rr.tomb.Kill(rr.loop()) + }() + return rr +} + +func (rr *Resumer) String() string { + return fmt.Sprintf("resumer") +} + +func (rr *Resumer) Kill() { + rr.tomb.Kill(nil) +} + +func (rr *Resumer) Stop() error { + rr.tomb.Kill(nil) + return rr.tomb.Wait() +} + +func (rr *Resumer) Wait() error { + return rr.tomb.Wait() +} + +func (rr *Resumer) loop() error { + for { + select { + case <-rr.tomb.Dying(): + return tomb.ErrDying + case <-time.After(interval): + if err := rr.st.ResumeTransactions(); err != nil { + log.Errorf("worker/resumer: cannot resume transactions: %v", err) + } + } + } + panic("unreachable") +}
Index: worker/resumer/resumer_test.go === added file 'worker/resumer/resumer_test.go' --- worker/resumer/resumer_test.go 1970-01-01 00:00:00 +0000 +++ worker/resumer/resumer_test.go 2013-06-13 15:29:49 +0000 @@ -0,0 +1,28 @@ +// Copyright 2013 Canonical Ltd. +// Licensed under the AGPLv3, see LICENCE file for details. + +package resumer_test + +import ( + . "launchpad.net/gocheck" + "launchpad.net/juju-core/juju/testing" + coretesting "launchpad.net/juju-core/testing" + "launchpad.net/juju-core/worker/resumer" + stdtesting "testing" +) + +func TestPackage(t *stdtesting.T) { + coretesting.MgoTestPackage(t) +} + +type ResumerSuite struct { + testing.JujuConnSuite +} + +var _ = Suite(&ResumerSuite{}) + +func (s *ResumerSuite) TestRunStop(c *C) { + rr := resumer.NewResumer(s.State) + + c.Assert(rr.Stop(), IsNil) +}
« Back to merge proposal
Reviewers: mp+169234_ code.launchpad. net,
Message:
Please take a look.
Description:
resumer: periodically resume transaction
The resumer is a periodically worker which is
resuming pending transactions in state each
minute.
https:/ /code.launchpad .net/~themue/ juju-core/ 026-transaction -resumer/ +merge/ 169234
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/10266043/
Affected files: resumer/ resumer. go resumer/ resumer_ test.go
A [revision details]
M state/state.go
A worker/
A worker/
Index: [revision details] 20130613115315- e58eqa122kc07o1 a
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: state/state.go
=== modified file 'state/state.go'
--- state/state.go 2013-06-12 02:45:22 +0000
+++ state/state.go 2013-06-13 15:29:49 +0000
@@ -1123,6 +1123,11 @@
return nil
}
+// ResumeTransactions resumes all pending transactions. ons() error { ResumeAll( )
+func (st *State) ResumeTransacti
+ return st.runner.
+}
+
var tagPrefix = map[byte]string{
'm': "machine-",
's': "service-",
Index: worker/ resumer/ resumer. go resumer/ resumer. go' resumer/ resumer. go 1970-01-01 00:00:00 +0000 resumer/ resumer. go 2013-06-13 15:29:49 +0000 net/juju- core/log" net/juju- core/state" net/tomb" Kill(rr. loop()) "resumer" ) After(interval) : nsactions( ); err != nil { "worker/ resumer: cannot resume transactions: %v", err) unreachable" )
=== added file 'worker/
--- worker/
+++ worker/
@@ -0,0 +1,62 @@
+// Copyright 2012, 2013 Canonical Ltd.
+// Licensed under the AGPLv3, see LICENCE file for details.
+
+package resumer
+
+import (
+ "fmt"
+ "launchpad.
+ "launchpad.
+ "launchpad.
+ "time"
+)
+
+// interval sets how often the resuming is called.
+const interval = time.Minute
+
+// Resumer is responsible for a periodical resuming of pending
transactions.
+type Resumer struct {
+ tomb tomb.Tomb
+ st *state.State
+}
+
+// NewResumer ...
+func NewResumer(st *state.State) *Resumer {
+ rr := &Resumer{st: st}
+ go func() {
+ defer rr.tomb.Done()
+ rr.tomb.
+ }()
+ return rr
+}
+
+func (rr *Resumer) String() string {
+ return fmt.Sprintf(
+}
+
+func (rr *Resumer) Kill() {
+ rr.tomb.Kill(nil)
+}
+
+func (rr *Resumer) Stop() error {
+ rr.tomb.Kill(nil)
+ return rr.tomb.Wait()
+}
+
+func (rr *Resumer) Wait() error {
+ return rr.tomb.Wait()
+}
+
+func (rr *Resumer) loop() error {
+ for {
+ select {
+ case <-rr.tomb.Dying():
+ return tomb.ErrDying
+ case <-time.
+ if err := rr.st.ResumeTra
+ log.Errorf(
+ }
+ }
+ }
+ panic("
+}
Index: worker/ resumer/ resumer_ test.go resumer/ resumer_ test.go' resumer/ resumer_ test.go 1970-01-01 00:00:00 +0000 resumer/ resumer_ test.go 2013-06-13 15:29:49 +0000 net/gocheck" net/juju- core/juju/ testing" net/juju- core/testing" net/juju- core/worker/ resumer" MgoTestPackage( t) JujuConnSuite ResumerSuite{ }) NewResumer( s.State)
=== added file 'worker/
--- worker/
+++ worker/
@@ -0,0 +1,28 @@
+// Copyright 2013 Canonical Ltd.
+// Licensed under the AGPLv3, see LICENCE file for details.
+
+package resumer_test
+
+import (
+ . "launchpad.
+ "launchpad.
+ coretesting "launchpad.
+ "launchpad.
+ stdtesting "testing"
+)
+
+func TestPackage(t *stdtesting.T) {
+ coretesting.
+}
+
+type ResumerSuite struct {
+ testing.
+}
+
+var _ = Suite(&
+
+func (s *ResumerSuite) TestRunStop(c *C) {
+ rr := resumer.
+
+ c.Assert(rr.Stop(), IsNil)
+}