-
Notifications
You must be signed in to change notification settings - Fork 7
Update jlhose.go #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -34,7 +34,10 @@ import ( | |
| "encoding/json" | ||
| "flag" | ||
| "fmt" | ||
| _ "github.com/bmizerany/pq" | ||
| _ "github.com/lib/pq" | ||
| // More up to date version of library | ||
| // Including talk about LISTEN/NOTIFY | ||
| // https://github.com/lib/pq/pull/106 | ||
| "github.com/donovanhide/eventsource" | ||
| "net" | ||
| "net/http" | ||
|
|
@@ -67,10 +70,12 @@ func (art *articleEvent) Id() string { | |
| // not too bad in practice - should always be ascending. | ||
| // But because stuff can be rescrapeduse lastscraped as id? | ||
| // or date + id concatenation? | ||
| // Maybe MAX(created,lastscraped) as unixtime with id concatenated? | ||
| return strconv.Itoa(art.id) | ||
| } | ||
|
|
||
| func (art *articleEvent) Event() string { | ||
| // This probably should be more specific, ie. "add", "update" and maybe even "delete" | ||
| return "article" | ||
| } | ||
|
|
||
|
|
@@ -93,6 +98,7 @@ func findLatest(db *sql.DB) string { | |
| } | ||
|
|
||
| // pumpArticles streams out a batch of articles starting just after lastEventID | ||
| // If you implement the registry interface this function might become a bit simpler, and just process a single article at a time | ||
|
Owner
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. You mean the Repository interface? |
||
| func pumpArticles(lastEventID string, db *sql.DB, eventServer *eventsource.Server) string { | ||
| batchSize := 1000 | ||
|
|
||
|
|
@@ -146,6 +152,7 @@ func main() { | |
|
|
||
| srv := eventsource.NewServer() | ||
| defer srv.Close() | ||
| // Channel should probably be "/article" if you decide to use the event field to dictate the action required by the client | ||
| http.HandleFunc("/new", srv.Handler("article")) | ||
| l, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally thought so, but I've changed my mind. Different event types require that sources are stateful - that they have a concept of history and know which documents they've sent out previously. While journalisted has this info, other sources won't. I think we should be aiming to keep the burden of scrapers as low as possible.
it also implies that the consumer of the document stream is in-sync with the source. Which isn't necessarily the case (eg journalisted rescraping and sending out an update for an old article which churnalism doesn't have).
So, while it's more work on the consumer (ie churnalism) side to check if incoming docs are already in the system, it makes scrapers vastly simpler, and we plan to write a lot more scrapers than consumers...
As long as scrapers are consistent with their document ordering and lastEventId scheme, the checking on the consumer side should be minimal - if the consumer gives a "lastEventId" to a source when it connects, it can be confident that it won't be served up some huge backlog of documents it's already been sent.
Blah. Not sure I'm being clear about this. I'll write an eventsource adaptor for a scraperwiki press release scraper to try and illustrate things a bit better.