Comments (2)
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.
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)
- is there any plan to support the Windows platform ? HOT 4
- Normalize task args & kwargs for uniqueness/locking
- Add CLI commands HOT 3
- Redis migration script
- Add endpoint that identifies queues with tasks but not in config
- Proposing a PR to fix a few small typos HOT 1
- queue a task from a PHP script? HOT 1
- Fix hard_timeout in parent process when stored on task function
- Attempt to modify a readonly table script HOT 3
- Task submission by string?
- Add Type Checking HOT 1
- Allow limiting the number of task executions kept in Redis HOT 1
- Refactor keys to avoid duplicate string literals
- Support Redis >= 6.2.7 (Lua readonly global tables) HOT 3
- TaskTiger add support for fork-less model HOT 1
- Only error tasks if the failure is within the task implementation HOT 4
- Make `func.delay` typed when decorating `func` with `@tiger.task`
- Asynchronous Redis HOT 2
- Inconsistent behavior in periodic function HOT 3
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 tasktiger.