Comments (11)
Hello, hibiken , how to use this lib in go-gin ?
from asynq.
Why I can't kill the process ?
from asynq.
@cielu Which OS are you using?
If you are on Windows, maybe something related to https://golang.org/pkg/os/signal/#hdr-Windows.
Please take a look at the Signal Wiki page on how to gracefully shutdown the background workers.
from asynq.
@hibiken macOS, But I start the worker in go-gin . Do you have any good idea ? thanks ..
I'm new at go
from asynq.
So you are using github.com/gin-gonic/gin for your web framework, correct?
And are you starting the workers (bg.Run(handler)
) from your web server's main?
from asynq.
@hibiken Yes , that's right . Here is my main func code
func main() {
// Set Mode
gin.SetMode(setting.AppCfg.AppMode)
// Init router
router := routes.InitRouter()
// run
router.Run(":" + setting.AppCfg.AppPost)
// init asynq worker
asynqWorker.InitAsynqWorker()
// init asynq client
asynqClient.InitAsynqClient()
}
from asynq.
I see.
The intended use case of asynq
is that you use Client
to schedule tasks to be processed in the background outside of a user request, and have another process(main.go) to process those tasks in the background.
So you will create another main.go
apart from your web server.
So for example, you will have something like this in your web server's main file:
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
client := asynq.NewClient(/* redis conn opt */)
r.POST("/signup", func(c *gin.Context) {
t := asynq.NewTask("send_email", map[string]interface{}{"user_id": 42})
client.Schedule(t, time.Now())
// render html or json
})
r.Run()
}
and create a separate main.go
file for workers:
func main() {
r := &asynq.RedisClientOpt{
Addr: "localhost:6379",
}
bg := asynq.NewBackground(r, &asynq.Config{
Concurrency: 10,
})
bg.Run(handler)
}
from asynq.
Yeah . enhh, I got you . But , can i start the worker in one project ? I don't want separate it .That is a lot of trouble
thanks 😊
from asynq.
I see.
Background.Run
method will block and wait for a termination signal (OS signal TERM or INTERRUPT).
I think if you want to start the workers from your web server's main then try this:
func main() {
// Set Mode
gin.SetMode(setting.AppCfg.AppMode)
// Init router
router := routes.InitRouter()
bgDone := make(chan, struct{})
go func() {
bg := asynq.NewBackground(r, &asynq.Config{/* options */})
bg.Run(handler)
bgDone <- struct{}{}
}()
// run
router.Run(":" + setting.AppCfg.AppPost)
<-bgDone
}
If that doesn't work, then another option is to fork this repo and export Background.Start
and Background.Stop
methods (currently they are unexported) and call those to start and stop the background workers, those methods are non-blocking.
from asynq.
Ohh. Thank you very much !
from asynq.
Closing this issue for now
from asynq.
Related Issues (20)
- Enqueue Failing
- UNKNOWN: redis command error: SADD failed: READONLY You can't write against a read only replica. HOT 2
- [FEATURE REQUEST] https://github.com/golang/protobuf is Depercated
- [FEATURE REQUEST] Support dynamic queue HOT 3
- [FEATURE REQUEST] stop usage of the internal folder
- When release v1? HOT 1
- How to mark a task as completed externally HOT 1
- Add example for redict.io and NATS jetstream HOT 1
- [FEATURE REQUEST] Add callback for task state changes
- [BUG] EnqueueContext not the original context HOT 2
- [BUG] Errors trying to connect remote worker server to scheduler HOT 1
- [FEATURE REQUEST] Support for Fixed-Length Queues in Asynq
- Order of task execution HOT 2
- [BUG] The related methods of Inspector basically lack the transmission of ctx HOT 2
- [FEATURE REQUEST] customize serializer
- Discussion/Suggestion: Decoupling `x` and `tools` packages.
- [BUG] Unable to schedule a task HOT 1
- Timing issues when running certain tests
- [FEATURE REQUEST] Settable maxArchiveSize HOT 1
- [BUG] Delete archived task fail, when task has been evicted from archived zset. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asynq.