-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to define tasks in the Engine directly
To make examples less cumbersome.
- Loading branch information
Showing
8 changed files
with
93 additions
and
57 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 |
---|---|---|
@@ -1,30 +1,27 @@ | ||
import time | ||
import logging | ||
|
||
from spinach import Engine, Tasks, MemoryBroker | ||
from spinach import Engine, MemoryBroker | ||
|
||
|
||
logging.basicConfig( | ||
format='%(asctime)s - %(threadName)s %(levelname)s: %(message)s', | ||
level=logging.DEBUG | ||
) | ||
tasks = Tasks() | ||
spin = Engine(MemoryBroker()) | ||
|
||
|
||
@tasks.task(name='fast', queue='high-priority') | ||
@spin.task(name='fast', queue='high-priority') | ||
def fast(): | ||
time.sleep(1) | ||
|
||
|
||
@tasks.task(name='slow', queue='low-priority') | ||
@spin.task(name='slow', queue='low-priority') | ||
def slow(): | ||
time.sleep(10) | ||
|
||
|
||
spin = Engine(MemoryBroker()) | ||
spin.attach_tasks(tasks) | ||
|
||
tasks.schedule('slow') | ||
tasks.schedule('fast') | ||
spin.schedule('slow') | ||
spin.schedule('fast') | ||
|
||
spin.start_workers(number=1, queue='low-priority') | ||
spin.start_workers(number=1, queue='high-priority') |
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
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