This file contains hidden or 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
from flask import Flask, request, Response | |
import json | |
from pymongo import MongoClient | |
from datetime import datetime | |
client = MongoClient("mongodb://logging:password@lcoal:port/logging") | |
db = client['logging'] | |
post = db.log | |
# set expire time 7 days, once setuped, couldn't change it again. | |
post.ensure_index("CreateDate", expireAfterSeconds= 7*24*60*60 ) |
This file contains hidden or 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
import logging | |
import threading | |
import time | |
import logging.handlers | |
import os | |
class OneLineExceptionFormatter(logging.Formatter): | |
def formatException(self, exc_info): |
This file contains hidden or 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
@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") |
This file contains hidden or 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
from fabric.api import * | |
env.hosts = [ | |
'username1@ip:port', | |
'username2@ip:port', | |
'username3@ip:port', | |
] | |
env.passwords = { | |
'username1@ip:port': "password1", |
This file contains hidden or 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
from fabric.api import * | |
env.hosts = [ | |
'ip', | |
'ip', | |
'ip', | |
] | |
# Set the username | |
env.user = "username" | |
# Set the password [NOT RECOMMENDED] |
This file contains hidden or 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
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" |
This file contains hidden or 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
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 |
This file contains hidden or 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
. | |
├── _test_celery | |
| ├── __init__.py | |
| ├── celeryapp.py | |
| ├── run_tasks.py | |
| └── tasks.py | |
└── fabfile.py |
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |