add celery
This commit is contained in:
parent
b63239009f
commit
db65b4e7e9
13 changed files with 250 additions and 0 deletions
36
alembic/versions/2017_09_02_15_24.py
Normal file
36
alembic/versions/2017_09_02_15_24.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
"""New table UserWotTokes
|
||||||
|
|
||||||
|
Revision ID: 6c29ab667741
|
||||||
|
Revises: b3222bf2cedb
|
||||||
|
Create Date: 2017-09-02 15:24:41.692342
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '6c29ab667741'
|
||||||
|
down_revision = 'b3222bf2cedb'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_table(
|
||||||
|
'user_wot_tokens',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('user', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('expires_at', sa.Integer),
|
||||||
|
sa.Column('access_token', sa.String(256)),
|
||||||
|
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.ForeignKeyConstraint(['user'], ['user.id']),
|
||||||
|
sa.UniqueConstraint('user')
|
||||||
|
)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_table('user_wot_tokens')
|
||||||
|
pass
|
34
alembic/versions/2017_09_03_17_37.py
Normal file
34
alembic/versions/2017_09_03_17_37.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 34b1309f878a
|
||||||
|
Revises: 6c29ab667741
|
||||||
|
Create Date: 2017-09-03 17:37:21.158601
|
||||||
|
|
||||||
|
"""
|
||||||
|
from sqlalchemy.dialects.postgresql import ARRAY, HSTORE
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '34b1309f878a'
|
||||||
|
down_revision = '6c29ab667741'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_table(
|
||||||
|
'user_wot_data',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('user', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('created_at', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('data', HSTORE, default='{}'),
|
||||||
|
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.ForeignKeyConstraint(['user'], ['user.id']),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_table('user_wot_data')
|
27
config_file.ini
Normal file
27
config_file.ini
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
from datetime import timedelta
|
||||||
|
from celery.schedules import crontab
|
||||||
|
|
||||||
|
DEBUG=True
|
||||||
|
|
||||||
|
SECRET_KEY="super-secret"
|
||||||
|
|
||||||
|
SQLALCHEMY_DATABASE_URI="postgres://wot:wot@192.168.1.47/wot"
|
||||||
|
|
||||||
|
OPENID_FS_STORE_PATH="tmp"
|
||||||
|
|
||||||
|
WG_REDIRECT_URL="http://wot.anzhiganov.com/token"
|
||||||
|
WG_APPLICATION_ID="502910c1c785c3c7ca2e83c9e89bde02"
|
||||||
|
# WG_OPENID_URL=https://eu.wargaming.net/id/openid/
|
||||||
|
WG_OPENID_URL="https://wargaming.net/id/openid/"
|
||||||
|
WG_TOKEN_URL="https://api.worldoftanks.ru/wot/auth/login/"
|
||||||
|
|
||||||
|
# Celery configuration
|
||||||
|
CELERY_BROKER_URL = 'redis://192.168.1.47:6379/4'
|
||||||
|
CELERY_RESULT_BACKEND = 'redis://192.168.1.47:6379/4'
|
||||||
|
#CELERYBEAT_SCHEDULE = {
|
||||||
|
# 'wotstats.tasks.hello': {
|
||||||
|
# 'task': 'wotstats.tasks.hello',
|
||||||
|
# # 'schedule': timedelta(seconds=3)
|
||||||
|
# 'schedule': crontab(minute="*")
|
||||||
|
# },
|
||||||
|
#}
|
5
run_app.py
Normal file
5
run_app.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
from wots import app
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(host='0.0.0.0', debug=True)
|
2
run_celery.py
Normal file
2
run_celery.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
from wots import celery
|
3
wots.py
Normal file
3
wots.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from wotstats.init import init_app
|
||||||
|
|
||||||
|
app, celery = init_app()
|
4
wotstats/log.py
Normal file
4
wotstats/log.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
# log.setLevel(logging.DEBUG)
|
17
wotstats/models/userwotdata.py
Normal file
17
wotstats/models/userwotdata.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
from sqlalchemy.dialects.postgresql import ARRAY, HSTORE
|
||||||
|
from wotstats.database import db
|
||||||
|
|
||||||
|
|
||||||
|
class UserWotData(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
user = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
|
||||||
|
created_at = db.Column(db.DateTime, nullable=False)
|
||||||
|
# WG
|
||||||
|
data = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
|
||||||
|
# def __init__(self):
|
||||||
|
# pass
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<UserWotData id={} user={} created_at={}>'.format(self.id, self.user, self.created_at)
|
27
wotstats/models/userwotdetails.py
Normal file
27
wotstats/models/userwotdetails.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
from sqlalchemy.dialects.postgresql import ARRAY, HSTORE
|
||||||
|
from wotstats.database import db
|
||||||
|
|
||||||
|
|
||||||
|
class UserWotDetails(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
user = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
||||||
|
# next columns is WG data
|
||||||
|
nickname = db.Column(db.String(32), unique=True)
|
||||||
|
client_language = db.Column(db.String(3))
|
||||||
|
last_battle_time = db.Column(db.Integer)
|
||||||
|
account_id = db.Column(db.Integer)
|
||||||
|
created_at = db.Column(db.Integer)
|
||||||
|
updated_at = db.Column(db.Integer)
|
||||||
|
logout_at = db.Column(db.Integer)
|
||||||
|
private = db.Column(db.String(32))
|
||||||
|
global_rating = db.Column(db.String(32))
|
||||||
|
clan_id = db.Column(db.Integer)
|
||||||
|
#
|
||||||
|
# ForeignKeyConstraint(['user'], ['user.id'])
|
||||||
|
|
||||||
|
# def __init__(self):
|
||||||
|
# pass
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<User id={} user={} nickname={}>'.format(self.id, self.user, self.nickname)
|
26
wotstats/models/userwotstats.py
Normal file
26
wotstats/models/userwotstats.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
from sqlalchemy.dialects.postgresql import ARRAY, HSTORE
|
||||||
|
from wotstats.database import db
|
||||||
|
|
||||||
|
|
||||||
|
class UserWotStats(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
user = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
||||||
|
created_at = db.Column(db.DateTime, nullable=False)
|
||||||
|
# WG
|
||||||
|
clan = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
stronghold_skirmish = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
regular_team = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
trees_cut = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
company = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
all = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
stronghold_defense = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
historical = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
team = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
flags = db.Column(HSTORE, nullable=False, default={})
|
||||||
|
|
||||||
|
# def __init__(self):
|
||||||
|
# pass
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<UserWotStats id={} user={} created_at={}>'.format(self.id, self.user, self.created_at)
|
27
wotstats/models/userwottokens.py
Normal file
27
wotstats/models/userwottokens.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
from sqlalchemy.dialects.postgresql import ARRAY, HSTORE
|
||||||
|
from wotstats.database import db
|
||||||
|
# from wotstats.models.user import User
|
||||||
|
|
||||||
|
|
||||||
|
class UserWotTokens(db.Model):
|
||||||
|
"""
|
||||||
|
([
|
||||||
|
('status', u'ok'),
|
||||||
|
('access_token', u'5c2e54189009738a001060f04c2e00f43d22f71b'),
|
||||||
|
('nickname', u'CrazyPants1999'),
|
||||||
|
('account_id', u'69552613'),
|
||||||
|
('expires_at', u'1505570179')
|
||||||
|
])
|
||||||
|
"""
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
user = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
||||||
|
# next columns is WG data
|
||||||
|
expires_at = db.Column(db.Integer)
|
||||||
|
access_token = db.Column(db.String(256), nullable=True)
|
||||||
|
|
||||||
|
# def __init__(self):
|
||||||
|
# pass
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<User id={} user={} access_token={} expires_at={}>'.format(self.id, self.user, self.access_token, self.expires_at)
|
4
wotstats/pending_tasks.py
Normal file
4
wotstats/pending_tasks.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
from celery import Celery
|
||||||
|
|
||||||
|
celery = Celery()
|
38
wotstats/tasks/__init__.py
Normal file
38
wotstats/tasks/__init__.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import time
|
||||||
|
from datetime import timedelta
|
||||||
|
from flask import current_app
|
||||||
|
from wotstats.pending_tasks import celery
|
||||||
|
|
||||||
|
|
||||||
|
@celery.task(name='wotstats.tasks.hello')
|
||||||
|
def hello():
|
||||||
|
time.sleep(3)
|
||||||
|
# current_app.log.error('wdwqd')
|
||||||
|
# with current_app.test_request_context() as request:
|
||||||
|
# print('Hello {0!r}'.format(request))
|
||||||
|
print 111
|
||||||
|
|
||||||
|
|
||||||
|
@celery.task
|
||||||
|
def mail_welcome():
|
||||||
|
time.sleep(3)
|
||||||
|
# current_app.log.error('wdwqd')
|
||||||
|
# with current_app.test_request_context() as request:
|
||||||
|
# print('Hello {0!r}'.format(request))
|
||||||
|
print 111
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@celery.on_after_configure.connect
|
||||||
|
def setup_periodic_tasks(sender, **kwargs):
|
||||||
|
# Calls test('hello') every 10 seconds.
|
||||||
|
sender.add_periodic_task(10.0, hello.s(), name='add every 10')
|
||||||
|
|
||||||
|
# Calls test('world') every 30 seconds
|
||||||
|
# sender.add_periodic_task(30.0, test.s('world'), expires=10)
|
||||||
|
|
||||||
|
# Executes every Monday morning at 7:30 a.m.
|
||||||
|
# sender.add_periodic_task(
|
||||||
|
# crontab(hour=7, minute=30, day_of_week=1),
|
||||||
|
# test.s('Happy Mondays!'),
|
||||||
|
# )
|
Reference in a new issue