-A代表APP
celery -A tasks worker --loglevel=info -n nodemaster
-------------- celery@nodemaster v4.1.0 (latentcall)
---- **** -----
--- * *** * -- Darwin-17.3.0-x86_64-i386-64bit 2018-04-15 11:53:09
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: tasks:0x110b42400
- ** ---------- .> transport: redis://localhost:6379/0
- ** ---------- .> results: disabled://
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. tasks.sendmail
[2018-04-15 11:53:09,217: INFO/MainProcess] Connected to redis://localhost:6379/0
[2018-04-15 11:53:09,228: INFO/MainProcess] mingle: searching for neighbors
[2018-04-15 11:53:10,256: INFO/MainProcess] mingle: sync with 2 nodes
[2018-04-15 11:53:10,257: INFO/MainProcess] mingle: sync complete
[2018-04-15 11:53:10,270: INFO/MainProcess] celery@nodemaster ready.
celery -A tasks inspect registered
celery -A tasks inspect registered
-> celery@node2: OK
* tasks.sendmail
-> celery@nodemaster: OK
* tasks.sendmail
Python 3.4.3 (default, Nov 6 2015, 22:26:48)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from tasks import sendmail
>>> sendmail.delay(dict(to='celery@python.org'))
>>> sendmail.delay(dict(to='celery@python.org'))
>>> sendmail.delay(dict(to='celery@python.org'))
>>> sendmail.delay(dict(to='celery@python.org'))
>>> sendmail.delay(dict(to='celery@python.org'))
>>> sendmail.delay(dict(to='celery@python.org222222'))
>>> sendmail.delay(dict(to='celery@python.org2222223'))
>>> sendmail.delay(dict(to='celery@python.org2222227'))
>>>
#tasks.py
importtimefrom celery importCelery
celery= Celery('tasks', broker='redis://localhost:6379/0')
@celery.taskdefsendmail(mail):print('....sending mail to %s...' % mail['to'])
time.sleep(20.0)print('mail sent.')~