mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
rename ConsumeNonBlocking to ConsumeNonBlock
This commit is contained in:
parent
0c1f74cc73
commit
3de551eed6
@ -25,7 +25,7 @@ make deploy # deploy worker
|
|||||||
NOTE: Wrangler does not support running multiple workers interacting with the same _local_ queue. Therefore, for the demostrational purposes,
|
NOTE: Wrangler does not support running multiple workers interacting with the same _local_ queue. Therefore, for the demostrational purposes,
|
||||||
we use the same worker to both produce and consume messages from the queue. For a real-world scenario, please consider the differences
|
we use the same worker to both produce and consume messages from the queue. For a real-world scenario, please consider the differences
|
||||||
between [queues.Consume](https://github.com/syumai/workers/blob/main/cloudflare/queues/consumer.go#L65) and
|
between [queues.Consume](https://github.com/syumai/workers/blob/main/cloudflare/queues/consumer.go#L65) and
|
||||||
(queues.ConsumeNonBlocking)(https://github.com/syumai/workers/blob/main/cloudflare/queues/consumer.go#L75) functions.
|
(queues.ConsumeNonBlock)(https://github.com/syumai/workers/blob/main/cloudflare/queues/consumer.go#L75) functions.
|
||||||
|
|
||||||
1. Start the dev server.
|
1. Start the dev server.
|
||||||
```sh
|
```sh
|
||||||
|
@ -22,7 +22,7 @@ func handleErr(w http.ResponseWriter, msg string, err error) {
|
|||||||
func main() {
|
func main() {
|
||||||
// start Qeueue consumer.
|
// start Qeueue consumer.
|
||||||
// If we would not have an HTTP handler in this worker, we would use queues.Consume instead
|
// If we would not have an HTTP handler in this worker, we would use queues.Consume instead
|
||||||
queues.ConsumeNonBlocking(consumeBatch)
|
queues.ConsumeNonBlock(consumeBatch)
|
||||||
|
|
||||||
// start HTTP server
|
// start HTTP server
|
||||||
http.HandleFunc("/", handleProduce)
|
http.HandleFunc("/", handleProduce)
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Consumer is a function that received a batch of messages from Cloudflare Queues.
|
// Consumer is a function that received a batch of messages from Cloudflare Queues.
|
||||||
// The function should be set using Consume or ConsumeNonBlocking.
|
// The function should be set using Consume or ConsumeNonBlock.
|
||||||
// A returned error will cause the batch to be retried (unless the batch or individual messages are acked).
|
// A returned error will cause the batch to be retried (unless the batch or individual messages are acked).
|
||||||
// NOTE: to do long-running message processing task within the Consumer, use cloudflare.WaitUntil, this will postpone the message
|
// NOTE: to do long-running message processing task within the Consumer, use cloudflare.WaitUntil, this will postpone the message
|
||||||
// acknowledgment until the task is completed witout blocking the queue consumption.
|
// acknowledgment until the task is completed witout blocking the queue consumption.
|
||||||
@ -61,17 +61,17 @@ func ready()
|
|||||||
// Consume sets the Consumer function to receive batches of messages from Cloudflare Queues
|
// Consume sets the Consumer function to receive batches of messages from Cloudflare Queues
|
||||||
// NOTE: This function will block the current goroutine and is intented to be used as long as the
|
// NOTE: This function will block the current goroutine and is intented to be used as long as the
|
||||||
// only worker's purpose is to be the consumer of a Cloudflare Queue.
|
// only worker's purpose is to be the consumer of a Cloudflare Queue.
|
||||||
// In case the worker has other purposes (e.g. handling HTTP requests), use ConsumeNonBlocking instead.
|
// In case the worker has other purposes (e.g. handling HTTP requests), use ConsumeNonBlock instead.
|
||||||
func Consume(f Consumer) {
|
func Consume(f Consumer) {
|
||||||
consumer = f
|
consumer = f
|
||||||
ready()
|
ready()
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConsumeNonBlocking sets the Consumer function to receive batches of messages from Cloudflare Queues.
|
// ConsumeNonBlock sets the Consumer function to receive batches of messages from Cloudflare Queues.
|
||||||
// This function is intented to be used when the worker has other purposes (e.g. handling HTTP requests).
|
// This function is intented to be used when the worker has other purposes (e.g. handling HTTP requests).
|
||||||
// The worker will not block receiving messages and will continue to execute other tasks.
|
// The worker will not block receiving messages and will continue to execute other tasks.
|
||||||
// ConsumeNonBlocking should be called before setting other blocking handlers (e.g. workers.Serve).
|
// ConsumeNonBlock should be called before setting other blocking handlers (e.g. workers.Serve).
|
||||||
func ConsumeNonBlocking(f Consumer) {
|
func ConsumeNonBlock(f Consumer) {
|
||||||
consumer = f
|
consumer = f
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user