listeners and special handlers improvements (#412)

* listeners and special handlers improvements

* update runnerListener methods

* typo
This commit is contained in:
Pedro Nasser
2016-12-13 16:40:48 -02:00
committed by C Cirello
parent 2fd8570e45
commit 2a09a1c2a2
10 changed files with 207 additions and 168 deletions

View File

@@ -10,7 +10,6 @@ import (
"github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/ifaces"
"github.com/iron-io/functions/api/models"
"github.com/iron-io/functions/api/runner"
"github.com/iron-io/functions/api/runner/task"
@@ -18,19 +17,20 @@ import (
)
type Server struct {
Runner *runner.Runner
Router *gin.Engine
MQ models.MessageQueue
AppCreateListeners []ifaces.AppCreateListener
AppUpdateListeners []ifaces.AppUpdateListener
AppDeleteListeners []ifaces.AppDeleteListener
SpecialHandlers []ifaces.SpecialHandler
Enqueue models.Enqueue
Datastore models.Datastore
Runner *runner.Runner
Router *gin.Engine
MQ models.MessageQueue
Enqueue models.Enqueue
tasks chan task.Request
specialHandlers []SpecialHandler
appCreateListeners []AppCreateListener
appUpdateListeners []AppUpdateListener
appDeleteListeners []AppDeleteListener
runnerListeners []RunnerListener
tasks chan task.Request
singleflight singleflight // singleflight assists Datastore
Datastore models.Datastore
}
func New(ctx context.Context, ds models.Datastore, mq models.MessageQueue, r *runner.Runner, tasks chan task.Request, enqueue models.Enqueue) *Server {
@@ -65,24 +65,6 @@ func prepareMiddleware(ctx context.Context) gin.HandlerFunc {
}
}
func (s *Server) AddSpecialHandler(handler ifaces.SpecialHandler) {
s.SpecialHandlers = append(s.SpecialHandlers, handler)
}
func (s *Server) UseSpecialHandlers(ginC *gin.Context) error {
c := &SpecialHandlerContext{
server: s,
ginContext: ginC,
}
for _, l := range s.SpecialHandlers {
err := l.Handle(c)
if err != nil {
return err
}
}
return nil
}
func DefaultEnqueue(ctx context.Context, mq models.MessageQueue, task *models.Task) (*models.Task, error) {
ctx, _ = common.LoggerWithFields(ctx, logrus.Fields{"call_id": task.ID})
return mq.Push(ctx, task)