Example for task arguments?
Closed this issue ยท 3 comments
I poked through the code, and its not clear to me how task arguments work with this package. If you could provide a brief example, that would be super awesome :)
Thanks for using rworker, @josegonzalez ! Rworker was built following the Celery specs, so you should be able to send arguments to tasks in the same way you would do in Python:
from celery import Celery
app = Celery(...)
kwargs = {"a": 1, "b":0}
app.send_task("your_task_defined_in_rworker", kwargs=kwargs)
As far as I remember (I don't touch this project for a while ๐) and given the way Worker objects execute tasks, positional arguments are currently being ignored and only kwargs are used during task execution.
The python side makes sense, but how do I access the kwargs in the R task?
If you define your function with ellipsis, you should be able to just list it:
yourTask <- function(...) {
kwargs <- list(...)
a <- kwargs["a"]
b <- kwargs["b"]
# your function definition...
}
Or, you could just define your function with predetermined arguments:
yourTask <- function(a, b) {
print(a)
print(b)
# your function definition...
}
Have you tried any of these approaches? This should be enough for you to access the arguments. If you are having any more trouble, please let me know! ๐