Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Support plugin event #215

Merged
merged 0 commits into from
Nov 7, 2016
Merged

Conversation

ben181231
Copy link
Contributor

connect #199

@oursky-travis
Copy link
Collaborator

@ben181231, thanks for your PR! By analyzing the annotation information on this pull request, we identified @rickmak to be a potential reviewer

@ben181231 ben181231 force-pushed the lifecycle-hook branch 3 times, most recently from 0e28c90 to 4676178 Compare November 3, 2016 09:20
@royuen royuen assigned cheungpat and unassigned rickmak Nov 4, 2016
@ben181231 ben181231 changed the title WIP: Support plugin event Support plugin event Nov 4, 2016
@ben181231
Copy link
Contributor Author

@cheungpat Please help to review this PR.


import "github.com/skygeario/skygear-server/pkg/server/logging"

var log = logging.LoggerEntry("plugin-evnet")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/plugin-evnet/plugin-event/

@@ -123,6 +117,12 @@ func TestRun(t *testing.T) {
So(string(out), ShouldEqual, `"op hello:world"`)
})

Convey("event", func() {
out, err := transport.SendEvent("foo:bar", []byte{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer foo-bar here

if err != nil {
panic(fmt.Sprintf("Unable to get registration info from plugin. Error: %v", err))
// SendEvents sends event to all plugins
func (c *Context) SendEvents(name string, data []byte, async bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer SendEvent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to mention explicitly in the comment that async being false means the event messages are sent to each plugin one after or another, or that event messages are sent to all plugins at once, then wait for all operations to complete

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I will update the comment.

@cheungpat
Copy link
Contributor

Just adding a note that we still need schema-change event in RecordSaveHandler.

@ben181231 ben181231 force-pushed the lifecycle-hook branch 2 times, most recently from 3b926b7 to c24c83f Compare November 7, 2016 08:08
@ben181231
Copy link
Contributor Author

@cheungpat The PR is updated.

@@ -345,6 +347,17 @@ func (h *RecordSaveHandler) Handle(payload *router.Payload, response *router.Res
results = append(results, result)
}

if resp.SchemaUpdated && h.EventSender != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this section out of this function scope (incl or excl the if statement

@@ -51,8 +51,8 @@ type schemaField struct {
TypeName string `mapstructure:"type" json:"type"`
}

func (resp *schemaResponse) Encode(data map[string]skydb.RecordSchema) {
resp.Schemas = make(map[string]schemaFieldList)
func encodeRecordSchemas(data map[string]skydb.RecordSchema) map[string]schemaFieldList {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to recordutil or (new) schemautil.

Basically we try not to have different handler files (record and schema) with code calling code in other file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

return schemaMap
}

func sendSchemaChangedEvent(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea to move this in a recordutil/schemautil file

@@ -28,7 +28,7 @@ func TestExtend(t *testing.T) {
db := c.PublicDB().(*database)

Convey("return Resemble RecordSchema on second call", func() {
err := db.Extend("note", skydb.RecordSchema{
_, err := db.Extend("note", skydb.RecordSchema{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file tests Extend. At the very least you want to test the boolean return value from the Extend function.

@ben181231 ben181231 force-pushed the lifecycle-hook branch 5 times, most recently from 6903d38 to 63e5cb1 Compare November 7, 2016 11:14
@cheungpat
Copy link
Contributor

good job benlei!

@cheungpat cheungpat merged commit 63e5cb1 into SkygearIO:master Nov 7, 2016
@ben181231 ben181231 deleted the lifecycle-hook branch December 5, 2016 10:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants