Skip to content

Commit

Permalink
logging not ready
Browse files Browse the repository at this point in the history
  • Loading branch information
YoLoveLife committed Nov 16, 2017
1 parent 42971da commit b007f70
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ travis & django TestCase</br>

*关于我开发中遇到的问题 我会写在issues当中供有需要的朋友 :mag: 查询*</br>
*这些问题都是在查询了诸多资料并亲身尝试大量解决方案 :grimacing: 最后得出的结论*</br>
*您可以在issues中搜索question和help wanted查看我写的相关问题*</br>
*您可以在issues中搜索helper查看我写的相关问题*</br>
*如果未找到您关注的问题或者您对我的项目有建议请在issues和我讨论 :heart: 期待收到您的信息*</br>

## Contents
Expand Down
3 changes: 3 additions & 0 deletions apps/deveops/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import absolute_import,unicode_literals
from .celery import app as celery_app
__all__ = ['celery_app']
94 changes: 83 additions & 11 deletions apps/deveops/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,96 @@
# Author Yo
# Email [email protected]

from __future__ import absolute_import,unicode_literals
# from __future__ import absolute_import,unicode_literals
# import os
# from celery import Celery,platforms
# from execute.service import base as BaseTask
# os.environ.setdefault('DJANGO_SETTINGS_MODULE','deveops.settings')
# platforms.C_FORCE_ROOT = True
#
# app = Celery('deveops')
# app.config_from_object('django.conf:settings')
# from django.conf import settings
# app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

# from celery.schedules import crontab
# from celery.task import periodic_task

# @periodic_task(
# run_every=(crontab(minute='*',hour='*')),
# name="PingOnlineTask",
# ignore_result=True
# )
# def PingOnlineTask():
# # BaseTask.PingOnlineService()
# # from manager.models import Host
# # import time
# # host = Host.objects.all()[0]
# # host.info = str(time.time())
# # host.save()
# from manager.models import Host
# from execute.ansible.runner import YoRunner
# from execute.callback import ResultCallback
# from operation.models import PlayBook
# from django.conf import settings
#
# hosts = Host.objects.all()
# import time
# for host in hosts:
# host.info = str(time.time())
# host.save()
# runner = YoRunner(hosts=hosts, extra_vars={})
# runner.set_callback(ResultCallback())
# playbook = PlayBook.objects.filter(id=settings.PING_PLAYBOOK_TASK_ID)[0]
# ret = runner.run(playbook.tasks.all())


from __future__ import absolute_import, unicode_literals
import os
from celery import Celery,platforms
from execute.service import base as BaseTask
os.environ.setdefault('DJANGO_SETTINGS_MODULE','deveops.settings')
platforms.C_FORCE_ROOT = True
app = Celery('deveops')
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')

app = Celery('proj')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings')
from django.conf import settings
# Load task modules from all registered Django app configs.
from django.apps import apps
# app.autodiscover_tasks(lambda: [n.name for n in apps.get_app_configs()])
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

from celery.schedules import crontab
from celery.task import periodic_task

from celery.schedules import crontab
@periodic_task(
run_every=(crontab(minute='*',hour='*')),
name="PingOnlineTask",
run_every=(crontab(minute='*')),
name="execute.tasks.PingOnlineTask",
ignore_result=True
)
def PingOnlineTask():
BaseTask.PingOnlineService()
from manager.models import Host
import time
host = Host.objects.all()[0]
host.info = str(time.time())
host.save()

# @app.task(bind=True)
# def debug_task(self):
# print('Request: {0!r}'.format(self.request))
from celery.schedules import crontab
#
# app.conf.update(
# CELERYBEAT_SCHEDULE = {
# # Executes every Monday morning at 7:30 A.M
# 'add-every-monday-morning': {
# 'task': 'execute.tasks.PingOnlineTask',
# 'schedule': crontab(hour=7, minute=30, day_of_week=1),
# 'args': (16, 16),
# },
# }
# )
13 changes: 13 additions & 0 deletions apps/deveops/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
# Time 17-11-15
# Author Yo
# Email [email protected]

def PingOnlineTask():
# BaseTask.PingOnlineService()
from manager.models import Host
import time
host = Host.objects.all()[0]
host.info = str(time.time())
host.save()
1 change: 1 addition & 0 deletions apps/execute/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import absolute_import,unicode_literals
53 changes: 53 additions & 0 deletions apps/execute/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
# Time 17-11-14
# Author Yo
# Email [email protected]
# from __future__ import absolute_import

# from celery.schedules import crontab
# from celery.task import periodic_task
# from celery.utils.log import get_task_logger
# from execute.utils import scrapers
# import datetime
# logger = get_task_logger(__name__)
#
#
# @periodic_task(run_every=(crontab(minute="*")))
# def scraper_example():
# logger.info("Start task")
# now = datetime.now()
# result = scrapers.scraper_example(now.day, now.minute)
# logger.info("Task finished: result = %i" % result)

# from deveops import celery_app
#
# @celery_app.task
# def ddr():
# print('start send email to %s')
# import time
# time.sleep(5) #休息5秒
# print('success')
# return True
#
# from celery.schedules import crontab
# from celery.task import periodic_task
# @periodic_task(run_every=crontab(minute='*'))
# def some_task():
# print('periodic task test!!!!!')
# import time
# time.sleep(5)
# print('success')
# return True

# Create your tasks here
from __future__ import absolute_import, unicode_literals
from celery.task import task

@task(name='PingOnlineTask')
def PingOnlineTask():
from manager.models import Host
import time
host = Host.objects.all()[0]
host.info = str(time.time())
host.save()
5 changes: 5 additions & 0 deletions apps/execute/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
# Time 17-11-14
# Author Yo
# Email [email protected]
7 changes: 7 additions & 0 deletions apps/execute/utils/scrapers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
# Time 17-11-14
# Author Yo
# Email [email protected]
def scraper_example(a, b):
return a + b
82 changes: 82 additions & 0 deletions apps/logging.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
;[loggers]
;keys=root,log02
;
;[handlers]
;keys=hand01,hand02
;
;[formatters]
;keys=form01,form02
;
;[logger_parser]
;level=DEBUG
;handlers=hand01
;propagate=1
;qualname=compiler.parser
;
;[logger_root]
;level=NOTSET
;handlers=hand01
;
;[logger_log02]
;level=DEBUG
;handlers=hand02
;propagate=1
;qualname=compiler.parser
;
;[handler_hand01]
;class=StreamHandler
;level=NOTSET
;formatter=form01
;args=(sys.stdout,)
;
;[handler_hand02]
;class=FileHandler
;level=DEBUG
;formatter=form02
;args=('logs/myapp.log', 'w')
;
;[formatter_form01]
;format=F1 %(asctime)s %(levelname)s %(message)s
;datefmt=
;class=logging.Formatter
;
;[formatter_form02]
;format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s
;datefmt=%a, %d %b %Y %H:%M:%S
;class=logging.Formatter

[loggers]
keys=root,all,api

[handlers]
keys=fileHandler

[formatters]
keys=format

[logger_root]
level=INFO
handlers=fileHandler

[logger_all]
level=INFO
handlers=fileHandler
qualname=deveops

[logger_api]
level=INFO
handlers=fileHandler
qualname=deveops.api

[logger_api]
level=INFO
handlers=fileHandler

[handler_fileHandler]
class=FileHandler
level=INFO
formatter=format
args=('logs/deveops.log', 'w')

[formatter_format]
format=%(asctime)s [%(threadName)s:%(thread)d] [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s
1 change: 1 addition & 0 deletions apps/softlib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import absolute_import,unicode_literals
5 changes: 5 additions & 0 deletions apps/timeline/decorator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
# Time 17-11-16
# Author Yo
# Email [email protected]
20 changes: 20 additions & 0 deletions apps/timeline/decorator/manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
# Time 17-11-16
# Author Yo
# Email [email protected]

def decorator_manager(asset_id,api_name,):#host group storage
def wrapper(func):
def inner_wrapper():
print(name)
func()
return inner_wrapper
return wrapper

@decorator_host(name='ddr')
def ddr():
print('function')

if __name__ == '__main__':
ddr()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Django==1.11.3
logging==0.4.9.6
Jinja2==2.9.6
MySQL-python==1.2.5
Pillow==4.2.1
Expand Down

0 comments on commit b007f70

Please sign in to comment.