Celery异步任务实例

2024年1月21日 15:15 by wst

异步处理

在上一篇文章中,介绍了Celery的原理,这次我们来说下其中的异步任务。

第一步

创建一个文件夹demo, 然后在demo下创建admin.py,内容如下:

from celery import Celery

app = Celery('admin', broker="redis://:tecent987@100.144.155.133:6379/4", backend="redis://:tecent987@100.144.155.133:6379/5")

@app.task
def add(x, y):
    print("running...", x, y)
    return x+y

broker用于存储任务队列,backend用于存储任务执行结果。

第二步

在demo中创建文件run.py, 内容如下:

from admin import add

if __name__ == "__main__":

    add.delay(4,5)

第三步

打开一个命令行窗口,运行以下命令启动执行服务

celery -A admin worker --loglevel=info

第四步

抛一个任务给执行服务,创建文件run.py并运行, 内容如下:

from admin import add

if __name__ == "__main__":

    add.delay(4,5)

在实际项目中,这里可能是抛出一个处理大文件的任务。

第五步

查看结果,进入自己的redis控制台,查看结果(注意最后两行)如下:

(base) ubuntu@VM-0-13-ubuntu:~$ redis-cli -h 100.144.155.133
100.144.155.133:6379> auth tecent987
OK
100.144.155.133:6379> keys *
(empty list or set)
100.144.155.133:6379> select 4
OK
100.144.155.133:6379[4]> keys *
1) "_kombu.binding.celery"
2) "_kombu.binding.celery.pidbox"
3) "_kombu.binding.celeryev"
100.144.155.133:6379[4]> select 5
OK
100.144.155.133:6379[5]> keys *
1) "celery-task-meta-915a1314-4cd7-473e-acbc-d385e66d4f56"
2) "celery-task-meta-0b7378b6-5ccc-422f-b5b7-8eea92306001"
100.144.155.133:6379[5]> get celery-task-meta-0b7378b6-5ccc-422f-b5b7-8eea92306001
"{\"status\": \"SUCCESS\", \"result\": 9, \"traceback\": null, \"children\": [], \"date_done\": \"2024-01-21T03:40:51.306585\", \"task_id\": \"0b7378b6-5ccc-422f-b5b7-8eea92306001\"}"

总结

         本文主要讲述了怎么启动并执行一个简单异步处理任务。对于Celery本身的理解又更进一步。


Comments(124) Add Your Comment

Ifsfhe
lipitor 20mg tablet <a href="https://lipiws.top/">atorvastatin 10mg cost</a> atorvastatin 80mg over the counter
Dfawiq
buy ciprofloxacin - <a href="https://metroagyl.top/cefaclor/">keflex buy online</a> cheap augmentin 375mg
Pmgxze
cipro usa - <a href="https://cipropro.top/">cipro sale</a> clavulanate over the counter
Dpmbem
flagyl price - <a href="https://metroagyl.top/clindamycin/">clindamycin usa</a> zithromax 500mg over the counter
Dxpzdw
order ciplox without prescription - <a href="https://septrim.top/chloromycetin/">cheap chloramphenicol sale</a> erythromycin buy online
Zcdetl
valacyclovir online - <a href="https://gnantiviralp.com/zovirax/">zovirax 400mg price</a> zovirax 400mg over the counter
Cjpqra
ivermectin 6 mg pills - <a href="https://keflexin.top/aczone/">buy generic aczone for sale</a> order sumycin generic
Joayow
metronidazole 200mg over the counter - <a href="https://metroagyl.top/azithromycin/">zithromax canada</a> buy zithromax generic
Mitjdp
buy acillin pills for sale <a href="https://ampiacil.top/">where can i buy acillin</a> buy amoxicillin paypal
Mqaymg
purchase lasix online cheap - <a href="https://antipathogenc.com/">order furosemide 40mg online</a> how to get capoten without a prescription
Xuxpzd
metformin uk - <a href="https://gnantiacidity.com/combivir/">order epivir without prescription</a> order generic lincomycin 500mg
Uwgcsb
order zidovudine sale - <a href="https://canadiangnp.com/allopurinol/">buy allopurinol cheap</a> oral zyloprim 100mg
Aetogb
cost clozapine 50mg - <a href="https://genonlinep.com/altace/">order generic altace 10mg</a> order pepcid 20mg generic
Onxggj
buy quetiapine without a prescription - <a href="https://gnkantdepres.com/geodon/">order ziprasidone generic</a> buy eskalith no prescription
Ahzrpb
order clomipramine 25mg without prescription - <a href="https://antdeponline.com/cymbalta/">order duloxetine generic</a> order doxepin pills
Cccqat
order atarax - <a href="https://antdepls.com/endep/">brand endep</a> amitriptyline 10mg usa
Qpyhrn
buy amoxicillin pills - <a href="https://atbioxotc.com/erythromycin/">buy erythromycin 500mg for sale</a> how to buy ciprofloxacin
Wuwqmb
buy augmentin 625mg sale - <a href="https://atbioinfo.com/linezolid/">linezolid 600mg pills</a> buy baycip cheap
Xsyoze
cleocin 300mg drug - <a href="https://cadbiot.com/">cleocin 300mg generic</a> chloramphenicol usa
Rdefsv
oral zithromax 250mg - <a href="https://gncatbp.com/">zithromax 500mg pills</a> ciplox 500 mg cheap
Phsrbd
buy ventolin 2mg for sale - <a href="https://antxallergic.com/dftheo-24/">purchase theophylline online cheap</a> buy theo-24 Cr pills for sale
Qjpvjm
generic stromectol - <a href="https://antibpl.com/">cost of stromectol</a> oral cefaclor
Eaynef
desloratadine online order - <a href="https://rxtallerg.com/flixotidespray/">flixotide nasal sprays</a> albuterol online
Tkgath
depo-medrol uk - <a href="https://ntallegpl.com/">order medrol for sale</a> azelastine oral
Dzbadn
how to get glyburide without a prescription - <a href="https://prodeprpl.com/">glyburide 2.5mg canada</a> dapagliflozin drug
Ztnjen
pill repaglinide 1mg - <a href="https://depressinfo.com/jardiance25/">purchase jardiance for sale</a> order jardiance online
Vmzxee
metformin over the counter - <a href="https://arxdepress.com/">oral glucophage</a> order precose 25mg online cheap
Pqbtrn
buy lamisil 250mg generic - <a href="https://treatfungusx.com/xgrifulvinvs/">griseofulvin drug</a> grifulvin v tablet
Webqcp
semaglutide 14 mg generic - <a href="https://infodeppl.com/ddavpspray/">desmopressin usa</a> DDAVP over the counter
Yqvifz
buy cheap nizoral - <a href="https://antifungusrp.com/itraconazole100/">itraconazole 100 mg usa</a> sporanox pill
Oytedj
generic famciclovir 500mg - <a href="https://amvinherpes.com/gnvalaciclovir/">oral valcivir 1000mg</a> purchase valcivir without prescription
Vxfdrj
buy lanoxin sale - <a href="https://blpressureok.com/isoptinpillmg/">buy cheap generic verapamil</a> buy lasix generic diuretic
Flaklf
brand hydrochlorothiazide - <a href="https://norvapril.com/felodipine/">order felodipine sale</a> buy zebeta 5mg sale
Utmmqr
order metoprolol pills - <a href="https://bloodpresspl.com/">lopressor 50mg generic</a> adalat 30mg without prescription
Mygmgx
purchase nitroglycerin sale - <a href="https://nitroproxl.com/indapamide/">pill indapamide 2.5mg</a> diovan usa
Pptksq
rosuvastatin pills keeper - <a href="https://antcholesterol.com/caduet5mg/">caduet pills wax</a> caduet pills tide
Bgmyjq
simvastatin slope - <a href="https://canescholest.com/">zocor everyone</a> atorvastatin rule
Uqactg
buy viagra professional gratitude - <a href="https://edsildps.com/superavana/">super avana strain</a> levitra oral jelly party
Dihtew
dapoxetine pont - <a href="https://promedprili.com/fildena/">fildena today</a> cialis with dapoxetine clothe
Vbfbga
cenforce foreign - <a href="https://xcenforcem.com/">cenforce online bit</a> brand viagra online frequent
Matoep
brand cialis earnest - <a href="https://probrandtad.com/apcalissx/">apcalis devil</a> penisole rope
Xsuwvf
cialis soft tabs slay - <a href="https://supervalip.com/levitrasoft/">levitra soft pills tonight</a> viagra oral jelly online cave
Naqszq
brand cialis waste - <a href="https://probrandtad.com/alprostadilonline/">alprostadil cauldron</a> penisole brief
Isefgp
cialis soft tabs kitchen - <a href="https://supervalip.com/viagrasuperactive/">viagra super active online city</a> viagra oral jelly online slap
Tekngh
cenforce get - <a href="https://xcenforcem.com/brandviagrasildenafil/">brand viagra online remove</a> brand viagra pills method
Bnttrw
acne medication hungry - <a href="https://placnemedx.com/">acne treatment watcher</a> acne medication menace
Yfggwo
asthma medication pain - <a href="https://bsasthmaps.com/">asthma treatment energy</a> asthma medication birth
Ueywla
uti antibiotics lad - <a href="https://amenahealthp.com/">uti treatment build</a> uti medication american
Pygauy
prostatitis treatment dawn - <a href="https://xprosttreat.com/">prostatitis treatment pop</a> prostatitis pills fan
Xncsyh
valtrex pills four - <a href="https://gnantiviralp.com/">valtrex mumble</a> valtrex body
Qqjqgy
claritin pills rear - <a href="https://clatadine.top/">loratadine true</a> claritin pills plate
Ygplkj
claritin pills lead - <a href="https://clatadine.top/">claritin whose</a> claritin pills brief
Yjgoxf
dapoxetine bother - <a href="https://prilixgn.top/">dapoxetine memory</a> dapoxetine hit
Sjardb
promethazine vast - <a href="https://prohnrg.com/">promethazine mechanical</a> promethazine charm
Bmhuuy
ascorbic acid ice - <a href="https://ascxacid.com/">ascorbic acid death</a> ascorbic acid born
Rbhixw
clarithromycin teacher - <a href="https://gastropls.com/ranitidineonline/">ranitidine pills petunia</a> cytotec pills name
Vzifni
fludrocortisone pills fad - <a href="https://gastroplusp.com/omepprilosec/">omeprazole pills needle</a> prevacid jail
Riqqux
bisacodyl tablet - <a href="https://gastroinfop.com/oxybutynin/">order oxybutynin for sale</a> purchase liv52 generic
Zwvqfz
aciphex brand - <a href="https://gastrointesl.com/metoclopramide/">buy metoclopramide 20mg pills</a> purchase motilium without prescription
Pqxgax
bactrim 480mg oral - <a href="https://cotrioxazo.com/">cotrimoxazole sale</a> purchase tobramycin sale
Lhjeuo
order hydroquinone online cheap - <a href="https://dupsteron.com/">duphaston without prescription</a> order duphaston 10 mg without prescription
Eiopkb
dapagliflozin 10 mg uk - <a href="https://precarbos.com/">buy acarbose 50mg</a> acarbose order online
Ejuzlo
order griseofulvin 250mg without prescription - <a href="https://gemfilopi.com/">buy lopid without a prescription</a> lopid 300mg pill
Nslmhq
enalapril 10mg us - <a href="https://xalanoprost.com/">order latanoprost online</a> buy xalatan eye drops
Nfcbhg
dramamine over the counter - <a href="https://bisacolax.com/">order dimenhydrinate for sale</a> buy cheap generic actonel
Lkfqln
buy feldene pills - <a href="https://rivastilons.com/">buy rivastigmine 6mg online</a> buy generic rivastigmine
Bckzvv
monograph where to buy - <a href="https://etodograph.com/">cheap monograph</a> pletal 100 mg generic
Mnekfe
piracetam 800 mg without prescription - <a href="https://nootquin.com/efavirenz/">buy sustiva online cheap</a> cost sinemet 10mg
Quxhiq
order hydroxyurea generic - <a href="https://hydroydrinfo.com/methocarbamol/">robaxin 500mg us</a> methocarbamol 500mg usa
Nwavxd
depakote 500mg cheap - <a href="https://adepamox.com/mefloquine/">buy mefloquine paypal</a> topiramate 200mg generic
Nhzjdr
disopyramide phosphate medication - <a href="https://anorpica.com/lamotrigine/">lamictal 50mg us</a> buy thorazine generic
Kwpvla
purchase cyclophosphamide for sale - <a href="https://cycloxalp.com/stavudine/">buy zerit</a> buy generic trimetazidine for sale
Sxmaix
aldactone 25mg pill - <a href="https://aldantinep.com/phenytoin/">oral dilantin</a> buy revia 50mg
Bzpbkv
cyclobenzaprine oral - <a href="https://abflequine.com/prasugrel/">prasugrel 10mg brand</a> buy vasotec pills
Vbhylz
ondansetron order - <a href="https://azofarininfo.com/">buy cheap zofran</a> buy requip 1mg generic
Tznawr
cost ascorbic acid 500 mg - <a href="https://mdacidinfo.com/lopinavirritonavir/">buy lopinavir ritonavir no prescription</a> compro tablet
Igiebx
how to purchase durex gel - <a href="https://xalaplinfo.com/">where can i purchase durex gel</a> order xalatan
Otvjbc
leflunomide 10mg drug - <a href="https://infohealthybones.com/cartidin/">buy cartidin</a> purchase cartidin pill
Efeqii
rogaine order - <a href="https://hairlossmedinfo.com/">order generic minoxidil</a> finasteride price
Baxmgg
oral tenormin - <a href="https://heartmedinfox.com/sotalol/">betapace 40mg sale</a> buy carvedilol 6.25mg generic
Mmqzsi
order calan pills - <a href="https://infoheartdisea.com/">calan 120mg sale</a> buy tenoretic generic
Yfrsjd
purchase atorvastatin for sale - <a href="https://infoxheartmed.com/nebivolol/">bystolic usa</a> bystolic 20mg cost
Vfxgyh
lasuna cheap - <a href="https://infoherbalmz.com/himcolin/">purchase himcolin for sale</a> generic himcolin
Tsjlgg
noroxin online buy - <a href="https://gmenshth.com/flutamide/">cheap eulexin generic</a> buy confido without prescription
Aryfxa
speman usa - <a href="https://spmensht.com/finasteride/">cheap fincar pill</a> order fincar pill
Vkqghs
buy finax tablets - <a href="https://finmenura.com/">buy finax generic</a> uroxatral medication
Myrzsr
buy hytrin - <a href="https://hymenmax.com/dapoxetine/">purchase dapoxetine pill</a> buy dapoxetine 60mg online cheap
Kttyew
order oxcarbazepine 300mg online cheap - <a href="https://trileoxine.com/levothyroxine/">cheap synthroid 75mcg</a> buy synthroid 75mcg for sale
Wuhsuc
lactulose for sale - <a href="https://duphalinfo.com/betahistine/">order generic betahistine 16 mg</a> order betahistine
Pkoezx
imusporin eye drops - <a href="https://asimusxate.com/">order cyclosporine online</a> buy cheap generic colcrys
Ifvxjp
buy besivance for sale - <a href="https://besifxcist.com/carbocysteine/">buy carbocysteine for sale</a> buy cheap generic sildamax
Hvwrrl
deflazacort price - <a href="https://lazacort.com/">buy generic deflazacort</a> buy alphagan eye drops
Mhterh
order benemid 500mg online cheap - <a href="https://bendoltol.com/">buy generic benemid for sale</a> tegretol order
Ldfhee
order neurontin 100mg - <a href="https://aneutrin.com/sulfasalazine/">sulfasalazine 500 mg price</a> sulfasalazine 500 mg ca
Oynjiv
mebeverine online order - <a href="https://coloxia.com/">buy cheap mebeverine</a> generic cilostazol 100 mg
Jlaqkh
celecoxib 200mg ca - <a href="https://celespas.com/">buy celecoxib cheap</a> buy indocin
Jpheml
order rumalaya sale - <a href="https://rumaxtol.com/shallaki/">shallaki brand</a> buy cheap generic endep
Gndspf
brand diclofenac 50mg - <a href="https://dicloltarin.com/aspirin/">buy aspirin 75 mg online</a> order aspirin 75 mg for sale
Kapgen
buy mestinon online - <a href="https://mestonsx.com/azathioprine/">buy azathioprine without a prescription</a> imuran online buy
Birnft
cost diclofenac - <a href="https://vovetosa.com/animodipine/">nimodipine cost</a> purchase nimotop
Hudiaa
order mobic 7.5mg generic - <a href="https://meloxiptan.com/rtrizatriptan/">toradol sale</a> order toradol pill
Ubfnxt
lioresal pills - <a href="https://baclion.com/">oral baclofen</a> order feldene 20mg pills
Gsdiun
purchase artane pills - <a href="https://voltapll.com/diclofenacgel/">buy cheap emulgel</a> how to buy diclofenac gel
Qpgrqr
order isotretinoin 40mg pill - <a href="https://aisotane.com/asdeltasone/">deltasone 5mg generic</a> order generic deltasone 5mg
Nmqqlw
order cefdinir 300mg - <a href="https://omnixcin.com/clindamycin/">buy cleocin</a> buy cleocin generic
Oiryro
oral acticin - <a href="https://actizacs.com/tretinoin/">where to buy retin without a prescription</a> generic tretinoin gel
Ycyiyr
order prednisone without prescription - <a href="https://apreplson.com/">prednisone online buy</a> buy zovirax
Fdxuqh
order metronidazole sale - <a href="https://ametronles.com/">buy flagyl tablets</a> cenforce generic
Hfbobn
betamethasone without prescription - <a href="https://betnoson.com/">order generic betamethasone 20 gm</a> benoquin for sale online
Sbidgq
augmentin 1000mg canada - <a href="https://baugipro.com/">clavulanate generic</a> brand synthroid 100mcg
Vsbgvg
buy generic cleocin - <a href="https://clinycinpl.com/">buy generic cleocin 150mg</a> generic indocin 50mg
Wiefri
buy crotamiton sale - <a href="https://aeuracream.com/abactroban/">mupirocin cheap</a> cheap aczone
Svqzhk
hyzaar price - <a href="https://acephacrsa.com/">generic cephalexin 500mg</a> cephalexin 125mg without prescription
Ofinfw
buy cheap bupropion - <a href="https://bupropsl.com/orlistat/">cost xenical 120mg</a> order shuddha guggulu online
Hkpyib
oral progesterone - <a href="https://apromid.com/gynelotrimin/">ponstel order online</a> how to buy clomiphene
Aldlfl
capecitabine tablet - <a href="https://xelocap.com/naproxen/">purchase naprosyn generic</a> brand danazol
Ajmjdb
buy generic aygestin for sale - <a href="https://norethgep.com/bimatoprost/">bimatoprost cheap</a> cheap yasmin generic
Zzewok
order fosamax 35mg pills - <a href="https://pilaxmax.com/">buy fosamax 70mg online</a> provera us
Pcvvgt
order cabergoline online cheap - <a href="https://adostilin.com/premarin/">buy premarin pills</a> oral alesse
Imxaup
order estradiol without prescription - <a href="https://festrolp.com/letrozole/">femara sale</a> arimidex drug
Zffigh
シルデナフィル - 50mg/100mg - <a href="https://jpedpharm.com/">バイアグラは薬局で買える?</a> 正規品シアリス錠の正しい処方
Dnqemp
プレドニン 薬局で買える - <a href="https://jpaonlinep.com/jamoxicillin/">アモキシシリン 値段</a> アジスロマイシン 値段
Pufqxn
eriacta float - <a href="https://eriagra.com/fforzestf/">forzest mystery</a> forzest dwarf
Bruugq
プレドニン 副作用 - <a href="https://jpanfarap.com/">プレドニン 市販 おすすめ</a> イソトレチノインの購入