From 0533abf6a8716cae33e66cf87e04ff4511945f99 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 1 Jul 2015 16:30:57 -0700 Subject: [PATCH] Make priority queue lambda function return error over a channel --- ...-bucket-handlers.go => bucket-handlers.go} | 0 .../{api-definitions.go => definitions.go} | 0 ...eneric-handlers.go => generic-handlers.go} | 0 ...ogging-handlers.go => logging-handlers.go} | 0 ...-object-handlers.go => object-handlers.go} | 0 ...imit-handlers.go => ratelimit-handlers.go} | 0 .../api/{api-response.go => response.go} | 0 pkg/storage/pq/pq_test.go | 44 ++++++++++++++----- pkg/storage/pq/task.go | 4 +- 9 files changed, 34 insertions(+), 14 deletions(-) rename pkg/server/api/{api-bucket-handlers.go => bucket-handlers.go} (100%) rename pkg/server/api/{api-definitions.go => definitions.go} (100%) rename pkg/server/api/{api-generic-handlers.go => generic-handlers.go} (100%) rename pkg/server/api/{api-logging-handlers.go => logging-handlers.go} (100%) rename pkg/server/api/{api-object-handlers.go => object-handlers.go} (100%) rename pkg/server/api/{api-ratelimit-handlers.go => ratelimit-handlers.go} (100%) rename pkg/server/api/{api-response.go => response.go} (100%) diff --git a/pkg/server/api/api-bucket-handlers.go b/pkg/server/api/bucket-handlers.go similarity index 100% rename from pkg/server/api/api-bucket-handlers.go rename to pkg/server/api/bucket-handlers.go diff --git a/pkg/server/api/api-definitions.go b/pkg/server/api/definitions.go similarity index 100% rename from pkg/server/api/api-definitions.go rename to pkg/server/api/definitions.go diff --git a/pkg/server/api/api-generic-handlers.go b/pkg/server/api/generic-handlers.go similarity index 100% rename from pkg/server/api/api-generic-handlers.go rename to pkg/server/api/generic-handlers.go diff --git a/pkg/server/api/api-logging-handlers.go b/pkg/server/api/logging-handlers.go similarity index 100% rename from pkg/server/api/api-logging-handlers.go rename to pkg/server/api/logging-handlers.go diff --git a/pkg/server/api/api-object-handlers.go b/pkg/server/api/object-handlers.go similarity index 100% rename from pkg/server/api/api-object-handlers.go rename to pkg/server/api/object-handlers.go diff --git a/pkg/server/api/api-ratelimit-handlers.go b/pkg/server/api/ratelimit-handlers.go similarity index 100% rename from pkg/server/api/api-ratelimit-handlers.go rename to pkg/server/api/ratelimit-handlers.go diff --git a/pkg/server/api/api-response.go b/pkg/server/api/response.go similarity index 100% rename from pkg/server/api/api-response.go rename to pkg/server/api/response.go diff --git a/pkg/storage/pq/pq_test.go b/pkg/storage/pq/pq_test.go index 0723d273f..b070324fa 100644 --- a/pkg/storage/pq/pq_test.go +++ b/pkg/storage/pq/pq_test.go @@ -30,24 +30,44 @@ type MySuite struct{} var _ = Suite(&MySuite{}) -func helloTask1() error { - fmt.Println("Hello task1") - return nil +func helloTask1() <-chan error { + errCh := make(chan error) + go func() { + defer close(errCh) + println("Hello task1") + errCh <- nil + }() + return errCh } -func helloTask2() error { - fmt.Println("Hello task2") - return nil +func helloTask2() <-chan error { + errCh := make(chan error) + go func() { + defer close(errCh) + println("Hello task2") + errCh <- nil + }() + return errCh } -func newJob1() error { - fmt.Println("New Job1") - return nil +func newJob1() <-chan error { + errCh := make(chan error) + go func() { + defer close(errCh) + println("New Job1") + errCh <- nil + }() + return errCh } -func newJob2() error { - fmt.Println("New Job2") - return nil +func newJob2() <-chan error { + errCh := make(chan error) + go func() { + defer close(errCh) + println("New Job2") + errCh <- nil + }() + return errCh } func (s *MySuite) TestPQ(c *C) { diff --git a/pkg/storage/pq/task.go b/pkg/storage/pq/task.go index 1c092fbd5..9a1f3e84d 100644 --- a/pkg/storage/pq/task.go +++ b/pkg/storage/pq/task.go @@ -18,7 +18,7 @@ package pq // Task container for any generic tasks type Task struct { - job func() error + job func() <-chan error priority int } @@ -34,5 +34,5 @@ func (t Task) UpdatePriority(p int) { // Execute execute current task func (t Task) Execute() error { - return t.job() + return <-t.job() }