| 85 | } |
| 86 | |
| 87 | func (cc *ChaincodeCustodian) Work(buildRegistry *container.BuildRegistry, builder ChaincodeBuilder, launcher ChaincodeLauncher) { |
| 88 | for { |
| 89 | cc.mutex.Lock() |
| 90 | if len(cc.choreQueue) == 0 && !cc.halt { |
| 91 | cc.cond.Wait() |
| 92 | } |
| 93 | if cc.halt { |
| 94 | cc.mutex.Unlock() |
| 95 | return |
| 96 | } |
| 97 | chore := cc.choreQueue[0] |
| 98 | cc.choreQueue = cc.choreQueue[1:] |
| 99 | cc.mutex.Unlock() |
| 100 | |
| 101 | if chore.runnable { |
| 102 | if err := launcher.Launch(chore.chaincodeID); err != nil { |
| 103 | logger.Warningf("could not launch chaincode '%s': %s", chore.chaincodeID, err) |
| 104 | } |
| 105 | continue |
| 106 | } |
| 107 | |
| 108 | if chore.stoppable { |
| 109 | if err := launcher.Stop(chore.chaincodeID); err != nil { |
| 110 | logger.Warningf("could not stop chaincode '%s': %s", chore.chaincodeID, err) |
| 111 | } |
| 112 | continue |
| 113 | } |
| 114 | |
| 115 | buildStatus, ok := buildRegistry.BuildStatus(chore.chaincodeID) |
| 116 | if ok { |
| 117 | logger.Debugf("skipping build of chaincode '%s' as it is already in progress", chore.chaincodeID) |
| 118 | continue |
| 119 | } |
| 120 | err := builder.Build(chore.chaincodeID) |
| 121 | if err != nil { |
| 122 | logger.Warningf("could not build chaincode '%s': %s", chore.chaincodeID, err) |
| 123 | } |
| 124 | buildStatus.Notify(err) |
| 125 | } |
| 126 | } |