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 / tasks.py
Created March 19, 2017 06:40
tasks.py
from __future__ import absolute_import
from test_celery.celeryapp import app
import time
import requests
from pymongo import MongoClient
client = MongoClient('10.211.55.12', 27018) # change the ip and port to your mongo database's
db = client.mongodb_test
collection = db.celery_test
@tonywangcn
tonywangcn / run_tasks.py
Last active March 19, 2017 06:42
run_tasks.py
from .tasks import longtime_add
import time
if __name__ == '__main__':
url = ['http://example1.com', 'http://example2.com', 'http://example3.com', 'http://example4.com'] # change them to your ur list.
for i in url:
result = longtime_add.delay(i)
print 'Task result:', result.result
@tonywangcn
tonywangcn / structures-of-file
Created March 19, 2017 06:47
structures-of-file
.
├── _test_celery
| ├── __init__.py
| ├── celeryapp.py
| ├── run_tasks.py
| └── tasks.py
└── fabfile.py
@tonywangcn
tonywangcn / fabric_run_parallel
Last active March 19, 2017 09:59
fabric_run_parallel
tony@tony-MBP:~/Desktop/Test$ fab install
[[email protected]:32772] Executing task 'install'
[[email protected]:32773] Executing task 'install'
[[email protected]:32774] Executing task 'install'
[[email protected]:32774] run: apt-get install dtach && apt-get install -y python-pip && pip install celery && pip install requests && pip install pymongo
[[email protected]:32773] run: apt-get install dtach && apt-get install -y python-pip && pip install celery && pip install requests && pip install pymongo
[[email protected]:32772] run: apt-get install dtach && apt-get install -y python-pip && pip install celery && pip install requests && pip install pymongo
from fabric.api import *
env.hosts = [
'10.211.55.12:32772',
'10.211.55.12:32773',
'10.211.55.12:32774',
]
# Set the username
env.user = "root"
@tonywangcn
tonywangcn / faric_server.py
Last active March 19, 2017 09:05
same user and password
from fabric.api import *
env.hosts = [
'ip',
'ip',
'ip',
]
# Set the username
env.user = "username"
# Set the password [NOT RECOMMENDED]
@tonywangcn
tonywangcn / fabric.py
Created March 19, 2017 09:04
different users and password
from fabric.api import *
env.hosts = [
'username1@ip:port',
'username2@ip:port',
'username3@ip:port',
]
env.passwords = {
'username1@ip:port': "password1",
@parallel
def install():
cmd = "celery -A test_celery worker --app=test_celery.celeryapp:app --concurrency=10 --loglevel=debug"
run("apt-get install dtach && apt-get install -y python-pip && pip install celery && pip install requests && pip install pymongo")
with settings(warn_only=True):
runResult = run("mkdir -p /root/code/test_celery")
if runResult.return_code == 1:
print 'file exists'
put("./test_celery/celeryapp.py", "/root/code/test_celery")
put("./test_celery/run_tasks.py", "/root/code/test_celery")
@tonywangcn
tonywangcn / logger.py
Last active April 24, 2017 13:49
rewrite logger handler to add some features
import logging
import threading
import time
import logging.handlers
import os
class OneLineExceptionFormatter(logging.Formatter):
def formatException(self, exc_info):