-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync_worker.py
70 lines (53 loc) · 1.78 KB
/
sync_worker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#-*- coding: utf-8 -*-
# import sys
# sys.path.append("../")
# import os
# from pathlib import Path
# print(Path(os.getcwd()).parent)
from celery import Celery
from celery.signals import worker_init
from celery.signals import worker_shutdown
from celery.bin.celery import result
import datetime
import requests
import json
import time
import random
import threading
from common import syncLogic
from common.util.statics import *
import logging
import logging.handlers
with open('./key/conf.json') as conf_json:
conf = json.load(conf_json)
app = Celery('tasks', broker='amqp://'+conf['rabbitmq']['user']+':'+conf['rabbitmq']['password']+'@'+conf['rabbitmq']['hostname']+'//')
@worker_init.connect
def init_worker(**kwargs):
print('init')
@worker_shutdown.connect
def shutdown_worker(**kwargs):
print('shut')
#codereview
#nametask를 쓰느 이유.
@app.task(name='task')
def worker(data):
mylogger = logging.getLogger()
mylogger.setLevel(logging.DEBUG)
rotatingHandler = logging.handlers.TimedRotatingFileHandler(filename='log/'+'log_sync_worker.log', when='midnight', interval=1, encoding='utf-8')
fomatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
rotatingHandler.setFormatter(fomatter)
mylogger.addHandler(rotatingHandler)
gameThread = threading.Thread(target=run, args=(data,))
gameThread.start()
def run(data):
print("celery data : " + str(data))
login_platform = data['login_platform']
apikey = data['apikey']
user = data['user']
if login_platform == 'naver' or login_platform == 'ical':
user_hashkey = data['user_hashkey']
syncInfo = syncLogic.caldav(user,apikey,login_platform,SYNC_TIME_STATE_BACKWARD)
elif login_platform == 'google':
syncInfo = syncLogic.google(user,apikey,SYNC_TIME_STATE_BACKWARD)
print("syncInfo : " + str(syncInfo))
return