Giter Site home page Giter Site logo

Comments (2)

AlecRosenbaum avatar AlecRosenbaum commented on July 28, 2024

In order to pass the function to the worker, we need to be able to serialize a dotted path to the task, which is then used to import and run the task on the worker side.

If you define tasks like this, my_task.__name__ == 'MyTask', so the worker ends up running module.MyTask(*args, **kwargs). I'm not aware of a way to programmatically generate a dotted path to a callable global variable, which is essentially what my_task is in this example. I have a feeling it's not possible to do from the object-definition side because you could end up with ambiguous scenarios when you have multiple references to the same object. It might be possible if you try to get a stack trace and inspect it looking for an assignment, but that would be really messy and unreliable.

There's a pretty nasty way to work around it that I wouldn't recommend, which would be setting __name__ after init to match the global name:

task = MyTask(echo=3)
task.__name__ = 'my_task'
my_task = tiger.task(task)

I'm sure your real scenario is more complicated, but in this example (assuming I couldn't change MyTask) I'd probably write something like this:

@tiger.task
def my_task(*args, **kwargs):
	return MyTask(echo=3)(*args, **kwargs)

from tasktiger.

AlecRosenbaum avatar AlecRosenbaum commented on July 28, 2024

In short, I don't foresee us adding support for this type of usage primarily because I'm not aware of a reliable way to get an importable path to the task when they're defined like this.

For now I'm going to close the issue but feel free to reopen if there's a good way to solve the problem I posed above that I'm just not aware of. Alternatively if you can provide more details on the real use case that invalidates my approach above, I'll try to respond to any additional comments when I get a chance.

from tasktiger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.