-
Notifications
You must be signed in to change notification settings - Fork 9
Rename Worker in master package to WorkerClient #10
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,9 +7,9 @@ import ( | |||||||||
| ) | ||||||||||
|
|
||||||||||
| type Master struct { | ||||||||||
| workers []Worker | ||||||||||
| idleWorkers chan Worker | ||||||||||
| linksCh chan []string | ||||||||||
| workerClients []WorkerClient | ||||||||||
| idleWorkerClients chan WorkerClient | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Thank you making the changes. I feel calling them workers is more natural in this code. You may disagree though. |
||||||||||
| linksCh chan []string | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func (m *Master) ExploreWebsite(ctx context.Context, siteURL string) { | ||||||||||
|
|
@@ -46,11 +46,11 @@ func (m *Master) ExploreWebsite(ctx context.Context, siteURL string) { | |||||||||
| } | ||||||||||
| case link := <-linkCh: | ||||||||||
| go func(link string) { | ||||||||||
| // process the current site there is idle worker | ||||||||||
| worker := <-m.idleWorkers | ||||||||||
| // process the current site there is idle workerClients | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| worker := <-m.idleWorkerClients | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| err := worker.FetchLinks(ctx, link) | ||||||||||
| if err != nil { | ||||||||||
| m.idleWorkers <- worker | ||||||||||
| m.idleWorkerClients <- worker | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| } | ||||||||||
| }(link) | ||||||||||
| case <-done: | ||||||||||
|
|
@@ -62,21 +62,21 @@ func (m *Master) ExploreWebsite(ctx context.Context, siteURL string) { | |||||||||
| func (m *Master) FinishExtractingLinks(workerID int, links []string) { | ||||||||||
| m.linksCh <- links | ||||||||||
| go func() { | ||||||||||
| m.idleWorkers <- m.workers[workerID] | ||||||||||
| m.idleWorkerClients <- m.workerClients[workerID] | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| }() | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func (m *Master) RegisterWorker(worker Worker) int { | ||||||||||
| workID := len(m.workers) | ||||||||||
| m.workers = append(m.workers, worker) | ||||||||||
| func (m *Master) RegisterWorker(workerClient WorkerClient) int { | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| workID := len(m.workerClients) | ||||||||||
| m.workerClients = append(m.workerClients, workerClient) | ||||||||||
| go func() { | ||||||||||
| m.idleWorkers <- worker | ||||||||||
| m.idleWorkerClients <- workerClient | ||||||||||
| }() | ||||||||||
| return workID | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func newMaster() *Master { | ||||||||||
| return &Master{ | ||||||||||
| idleWorkers: make(chan Worker), | ||||||||||
| idleWorkerClients: make(chan WorkerClient), | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,13 +23,13 @@ func (s Server) ExploreWebsite(ctx context.Context, request *proto.ExploreWebsit | |||||
| } | ||||||
|
|
||||||
| func (s Server) RegisterWorker(ctx context.Context, request *proto.RegisterWorkerRequest) (*proto.RegisterWorkerResponse, error) { | ||||||
| worker := newWorker(request.Ip, int(request.Port), request.Secret) | ||||||
| err := worker.Connect() | ||||||
| workerClient := newWorkerClient(request.Ip, int(request.Port), request.Secret) | ||||||
| err := workerClient.Connect() | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| workerID := s.master.RegisterWorker(worker) | ||||||
| fmt.Printf("Worker registed: ID(%d) IP(%s) PORT(%d) SECRET(%s)\n", workerID, request.Ip, int(request.Port), request.Secret) | ||||||
| workerID := s.master.RegisterWorker(workerClient) | ||||||
| fmt.Printf("WorkerClient registed: ID(%d) IP(%s) PORT(%d) SECRET(%s)\n", workerID, request.Ip, int(request.Port), request.Secret) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| return &proto.RegisterWorkerResponse{ | ||||||
| WorkerId: int32(workerID), | ||||||
| }, nil | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.