-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Attumm/add_decorator_workers
Add decorators flow with python magic
- Loading branch information
Showing
10 changed files
with
736 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import sys | ||
|
||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
|
||
from meesee import Meesee # noqa: E402 | ||
|
||
config = { | ||
"namespace": "removeme", | ||
"key": "tasks", | ||
"redis_config": {}, | ||
"maxsize": 100, | ||
"timeout": 1, | ||
} | ||
|
||
|
||
@Meesee.worker() | ||
def func_a(item, worker_id): | ||
print('func: {}, worker_id: {}, item: {}'.format('func_a', worker_id, item)) | ||
|
||
|
||
@Meesee.worker() | ||
def func_b(item, worker_id): | ||
print('func: {}, worker_id: {}, item: {}'.format('func_b', worker_id, item)) | ||
|
||
|
||
@Meesee.worker() | ||
def func_c(item, worker_id): | ||
print('func: {}, worker_id: {}, item: {}'.format('func_c', worker_id, item)) | ||
|
||
|
||
if __name__ == '__main__': | ||
workers = int(sys.argv[sys.argv.index('-w') + 1]) if '-w' in sys.argv else 10 | ||
Meesee.start_workers(workers=workers, config=config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
import sys | ||
|
||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
|
||
from meesee import Meesee # noqa: E402 | ||
|
||
|
||
config = { | ||
"namespace": "removeme", | ||
"key": "tasks", "redis_config": {}, | ||
"maxsize": 100, | ||
"timeout": 1, | ||
} | ||
|
||
box = Meesee(config) | ||
|
||
|
||
@box.worker() | ||
def foobar(item, worker_id): | ||
print('func: foobar, worker_id: {}, item: {}'.format(worker_id, item)) | ||
|
||
|
||
@box.worker() | ||
def name_of_the_function(item, worker_id): | ||
print('func: name_of_the_function, worker_id: {}, item: {}'.format(worker_id, item)) | ||
|
||
|
||
@box.worker(queue="passed_name") | ||
def passed_name_not_this_one(item, worker_id): | ||
print('func: passed_name_not_this_one, worker_id: {}, item: {}'.format(worker_id, item)) | ||
|
||
|
||
@box.produce(queue="passed_name") | ||
def produce_some_items(amount): | ||
yield from range(amount) | ||
|
||
|
||
@box.produce() | ||
def produce_to_foo(items): | ||
return items | ||
|
||
|
||
@box.worker_producer(input_queue="foo", output_queue="foobar") | ||
def foo(item, worker_id): | ||
print(f"{worker_id} {item} foo pass it too foobar") | ||
return [item,] | ||
|
||
|
||
if __name__ == '__main__': | ||
workers = int(sys.argv[sys.argv.index('-w') + 1]) if '-w' in sys.argv else 10 | ||
produce_some_items(10) | ||
items = [{"name": f"name{i}"} for i in range(10)] | ||
produce_to_foo(items) | ||
box.push_button(workers, wait=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.