Comments (6)
Thank you for the issue.
I think its great idea but it might also add burden of extra code to users.
You can achieve same effect by registering member functions instead.
Take a look at below example.
type MyObject struct {
MyInt int
}
func (mo *MyObject) add(a int, b int) int {
return a + b + mo.MyInt
}
func main() {
mo := &MyObject{999}
celeryBroker := gocelery.NewRedisCeleryBroker("localhost:6379", "")
celeryBackend := gocelery.NewRedisCeleryBackend("localhost:6379", "")
celeryClient, _ := gocelery.NewCeleryClient(celeryBroker, celeryBackend, 2)
celeryClient.Register("worker.add", mo.add)
go celeryClient.StartWorker()
time.Sleep(30 * time.Second)
celeryClient.StopWorker()
}
from gocelery.
Even if you CAN pass a bound method to Register
(does it need to have a pointer receiver to do this?), in idiomatic Go this kind of thing is usually accomplished using an interface. Most use cases for Celery I've experienced in production environments involve a lot of moving pieces and are rarely very simple functions like this.
If you don't want to change the API and still have this as a feature, a runtime type assertion could determine if the second parameter of Register
implements the Task
interface and can handle it differently.
from gocelery.
Above code works and pointer to interface is not correct type to hold pointer to struct.
I assume that you want to model after Celery task class in Python implementation.
Certainly your approach would mirror that.
You are always welcome to create pull request =)
from gocelery.
I think you're misunderstanding what I'm trying to say. The article you linked is about pointers to interfaces. I'm referring to the method you're adding to register (add
) having a pointer receiver.
Regardless, I think a PR will clear up confusion. The "Celery task class" is the correct approach to take in Go.
from gocelery.
Oh I see what you mean.
It doesn't necessarily have to be pointer receiver. (I have tested)
As far as I understand, the difference is whether you want to pass object by reference or by value to the method.
Also one problem I can see is that gocelery only supports args at the moment (not kwargs).
I think it'd be difficult to map args in your model using json.
But I do agree that its more aligned with standard go practice to use interface.
Perhaps, args can be supported by anonymous function and kwargs can be supported by your model.
from gocelery.
Using interface would provide performance gain over using reflection.
Only arguments passed through kwargs
dictionary is supported using CeleryTask
interface.
merged at a14372d
from gocelery.
Related Issues (20)
- Fix failing github action due to golangci-lint HOT 1
- Support tasks without arguments HOT 1
- Only first return value is processed HOT 1
- Tasks without return value would cause panic when `Get` is called HOT 3
- Redis cluster support using redis-go
- Postgresql as broker HOT 6
- how to set the ETA ? HOT 2
- Does gocelery support querying task status via taskid? HOT 4
- Revoke task HOT 3
- Return struct from the func (cc *CeleryClient) Register(name string, task interface{}) HOT 1
- Support option functions
- can not get result by AMQP HOT 2
- gocelery fails to return tasks submitted before worker started
- Keep getting this error: amqp_backend: failed to acknowledge result message : delivery not initialized
- connection.close() does not work.
- Interest in a PostgreSQL result backend HOT 3
- Race-condition with worker task execution HOT 2
- Worker still accepts new tasks following shutdown
- Sharing a fork
- Can asynq dynamically add a scheduled task using the Rset API trigger?
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 gocelery.