Skip to content

Instantly share code, notes, and snippets.

View tonywangcn's full-sized avatar
🎯
Focusing

Tony Wang tonywangcn

🎯
Focusing
View GitHub Profile
@tonywangcn
tonywangcn / message_in_rabbitmq
Created March 19, 2017 06:29
messages in rabbitmq
root@rabbit:/# rabbitmqctl -q list_queues name messages messages_ready messages_unacknowledged
celery 9164 9004 160
celeryev.a38b8fc2-7cc9-4cea-acc1-50cf6120601d 0 0 0
celeryev.fdc57883-aa62-4623-95b5-29b713ff51f4 0 0 0
[email protected] 0 0 0
[email protected] 0 0 0
celeryev.0a6a638a-9f94-4767-a4e0-a708467a5363 0 0 0
celeryev.be44ef35-a82f-4461-aea4-8f82a5363d9b 0 0 0
[email protected] 0 0 0
37df9fdf-2d62-3106-8157-8800695cb9d4 816 816 0
@tonywangcn
tonywangcn / celeryapp.py
Created March 19, 2017 06:17
celeryapp.py
from __future__ import absolute_import
from celery import Celery
app = Celery('test_celery', broker='amqp://admin:[email protected]:5673', backend='rpc://', include=['test_celery.tasks'])
@tonywangcn
tonywangcn / running_worker
Created March 19, 2017 06:05
running celery worker in slave machine
root@ee6b8257af81:~/code# ps -ef | grep celery
root 900 1 0 06:02 ? 00:00:00 dtach -n /tmp/dtach.WL5S celery -A test_celery worker --app=test_celery.celeryapp:app --concurrency=10 --loglevel=debug
root 901 900 10 06:02 pts/1 00:00:00 /usr/bin/python /usr/local/bin/celery -A test_celery worker --app=test_celery.celeryapp:app --concurrency=10 --loglevel=debug
root 908 901 0 06:02 pts/1 00:00:00 /usr/bin/python /usr/local/bin/celery -A test_celery worker --app=test_celery.celeryapp:app --concurrency=10 --loglevel=debug
root 909 901 0 06:02 pts/1 00:00:00 /usr/bin/python /usr/local/bin/celery -A test_celery worker --app=test_celery.celeryapp:app --concurrency=10 --loglevel=debug
root 910 901 0 06:02 pts/1 00:00:00 /usr/bin/python /usr/local/bin/celery -A test_celery worker --app=test_celery.celeryapp:app --concurrency=10 --loglevel=debug
root 911 901 0 06:02 pts/1 00:00:00 /usr/bin/python /usr/local/bin/celery -A test_celery worker --app
@tonywangcn
tonywangcn / fabric_install_log
Created March 19, 2017 05:53
log of deploying remote server with fabric
[[email protected]:32772] Executing task 'install'
[[email protected]:32772] run: apt-get install screen && apt-get install -y python-pip && pip install celery && pip install requests && pip install pymongo
[[email protected]:32772] out:
[[email protected]:32772] out: Reading package lists... 0%
[[email protected]:32772] out:
[[email protected]:32772] out: Reading package lists... 0%
[[email protected]:32772] out:
[[email protected]:32772] out: Reading package lists... 1%
[[email protected]:32772] out:
[[email protected]:32772] out: Reading package lists... 6%
@tonywangcn
tonywangcn / ubuntu_instance_dockerfile
Created March 19, 2017 05:40
ubuntu dockerfile with ssh
FROM ubuntu:16.04
MAINTAINER TonyWang <[email protected]>
RUN apt-get update && apt-get install -y sudo && apt-get install -y software-properties-common python-software-properties && apt-get install net-tools && apt-get install -y iputils-ping && apt-get install -y vim && apt-get install -y tcptrack
RUN apt-get update && sudo add-apt-repository "deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse"
RUN sudo add-apt-repository "deb http://cn.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse"
RUN sudo add-apt-repository "deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse"
RUN sudo add-apt-repository "deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse"
RUN sudo add-apt-repository "deb http://cn.archive.ubuntu.com/ubuntu/ xenial-proposed main restricted universe multiverse"
RUN sudo add-apt-repository "deb http://archive.canonical.com/ubuntu/ xenial partner"
RUN sud
@tonywangcn
tonywangcn / ubuntu_instance
Created March 19, 2017 05:37
3 instances totally
root@ubuntu:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
94b052d141a9 ubuntu_python_latest "/usr/sbin/sshd -D" About an hour ago Up About an hour 0.0.0.0:32774->22/tcp ubuntu_instance03
ad1c39e6ba8c ubuntu_python_latest "/usr/sbin/sshd -D" About an hour ago Up About an hour 0.0.0.0:32773->22/tcp ubuntu_instance02
9736f94b4b2e ubuntu_python_latest "/usr/sbin/sshd -D" About an hour ago Up About an hour 0.0.0.0:32772->22/tcp ubuntu_instance01
from .tasks import longtime_add
import time
if __name__ == '__main__':
url = ['http://example1.com' , 'http://example2.com' , 'http://example3.com' , 'http://example4.com' , 'http://example5.com' , 'http://example6.com' , 'http://example7.com' , 'http://example8.com'] # change them to your ur list.
for i in url:
result = longtime_add.delay(i)
print 'Task result:',result.result
from __future__ import absolute_import
from test_celery.celery import app
import time,requests
from pymongo import MongoClient
client = MongoClient('10.1.1.234', 27018) # change the ip and port to your mongo database's
db = client.mongodb_test
collection = db.celery_test
post = db.test
@app.task(bind=True,default_retry_delay=10) # set a retry delay, 10 equal to 10s
def longtime_add(self,i):
celery==4.0.2
requests
pymongo==3.4.0
FROM python:2.7
ADD requirements.txt /app/requirements.txt
ADD ./test_celery/ /app/
WORKDIR /app/
RUN pip install -r requirements.txt
ENTRYPOINT celery -A test_celery worker --concurrency=20 --loglevel=info