This repository has been archived by the owner on Apr 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
data/ | ||
logs/ | ||
*.log | ||
|
||
server.nginx.conf | ||
supervisord.conf |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#coding: utf-8 | ||
|
||
from .book import * | ||
from .queue import * |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#coding: utf-8 | ||
|
||
from flask import current_app | ||
|
||
import api | ||
from api import LibraryNotFoundError | ||
|
||
from server.app import build | ||
from server.db import db | ||
from server.models import Book | ||
|
||
from .queue import book_queue | ||
|
||
|
||
__all__ = ['update_book', 'update_books'] | ||
|
||
|
||
def update_book(ctrlno): | ||
'''更新书籍信息 | ||
:param ctrlno: 书籍控制号 | ||
:param database: 数据库 | ||
TODO isolate location updating | ||
''' | ||
try: | ||
book_api = api.Book() | ||
book_infos = book_api.get(ctrlno) | ||
except LibraryNotFoundError: | ||
return | ||
|
||
app = build() | ||
with app.app_context(): | ||
book = Book.query.filter_by(ctrlno=ctrlno).first() | ||
if not book: | ||
return | ||
|
||
locations = book_infos.get('locations') | ||
book.location.available = len( | ||
filter(lambda x: x['status'] == u'可供出借', locations)) | ||
book.location.total = len(locations) | ||
db.session.commit() | ||
|
||
return book_infos | ||
|
||
|
||
def update_books(): | ||
'''更新所有书籍信息''' | ||
|
||
app = build() | ||
with app.app_context(): | ||
current_app.logger.debug('start updating all books...') | ||
for book in Book.query.all(): | ||
book_queue.enqueue(update_book, book.ctrlno) | ||
|
||
return True |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#coding: utf-8 | ||
|
||
from redis import Redis | ||
from rq import Queue | ||
|
||
|
||
__all__ = ['book_queue', 'user_queue'] | ||
|
||
|
||
_redis_connection = Redis() | ||
book_queue = Queue(name='book', connection=_redis_connection) | ||
user_queue = Queue(name='user', connection=_redis_connection) |