Open hupili opened 11 years ago
maybe, wrapper synchronous calls into threads is another, but poor, solution for these DELAYs https://github.com/iptux/snsapi/commit/db24686e73ce31fa186c7aacda9d515ad47dabe5
i'm considering whether to make a pull request, it havn't solve the underlying problem
Nice commit!
I think this is the current best solution for upper layer apps. However, it is not suitable to put that commit in the snspocket.
Instead of method by method modification, my suggestion is:
snsbase.py
, which make a method callback-able. {'platform':xxx, 'channel': xxx, 'method_param': xxx, 'callback_param': xxx, ... }
. This is to help callback functions operate in a stateless manner. Also, users can put some app-specific data in callback_param
so as to coordinate between several (probably simultaneous calls). The use cases are then:
make_callback
decorator can be used by many other components, even as a building block for the queue. pocket.json
, SNSPocket can dynamically decorate those methods in __init__
. SNSPocketCallback
which derives SNSPocket and make all methods defaultly callback-able. This way looks better for me before we have such async-queue facility. What do you think?
One prototype is implemented in sina-automator
It implements a leaky bucket for resource management. The rate_limit
decorator also has callback support. For resource management within one channel, the sina-automator
's lbucket suffices.
One still missing piece is the ability to coordinate resources between different channels. Note that when there are more and more channels, apps may want to simultaneously request them. Resources should be considered across channels, i.e. "Support per-platform / per-account / per-key locking.".
This feature will gradually enter SNSAPI starting from v0.7
.
@fqj1994 , please place a warning log message to notify users about possible interfaces changes of async related stuffs.
With the increasing number of channels, synchronous call to all methods causes larger and larger delay. Before it exceeds human tolerable span, we should consider an asynchronous message queue.
The queue:
Requires experienced Python developer and one who is familiar with SNSAPI framework.
Welcome any prototyping and restructuring effort to make the queue easy to implement.