示例#1
0
def test_create_dispatcher():
    docker_dispatcher = Dispatcher()
    assert docker_dispatcher is not None
示例#2
0
from dialog.v1.states import States, Headers
from core.utils import prepare_response
from dispatcher.filters import *
from dispatcher.dispatcher import Dispatcher
from aioalice.dispatcher.storage import DEFAULT_STATE
from core import actions
dp = Dispatcher()


@dp.request_handler_order(StatesListFilter([States.HELLO, DEFAULT_STATE]),
                          func=actions.new_session_new_user)
async def hello_new_user(alice_request, game, *args):
    _out = dict(
        responose_or_text=
        'Привет! Очень здорово, что ты хочешь посоревноваться и потренировать свою память! '
        '\n Мы будем по очереди называть слова, повторяя друг за другом. Кто первый допустит ошибку '
        '- выбывает из игры.',
        tts=
        'Прив+ет! - - -Очень зд+орово, - - -что ты хочешь посоревнов+аться - - -и -  '
        'потрениров+ать сво+ю п+амять! - - - - -Мы будем по очереди назыв+ать слова, - -повторяя другзадр+угом. '
    )
    game.set_state(States.SELECT_GAME_MODE)
    return alice_request.response(
        **prepare_response(_out, Headers.SELECT_GAME_MODE))


@dp.request_handler_order(StatesListFilter([States.HELLO, DEFAULT_STATE]),
                          func=actions.new_session_friend)
async def hello_friend(alice_request, game, stats, *args):
    _out = [
        dict(responose_or_text='Привет! Рада видеть тебя снова!',
示例#3
0
def test_start_dispatcher(docker_dispatcher: Dispatcher):
    docker_dispatcher.start()
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import logging
from config_parsing.config import Config
from dispatcher.dispatcher import Dispatcher

if __name__ == "__main__":
    try:
        if len(sys.argv) != 2:
            logging.critical(
                "Invalid amount of arguments\nUsage: main.py config.json")
            exit(1)

        config = Config(sys.argv[1].strip())
        dispatcher = Dispatcher(config)
        dispatcher.run_pipeline()
        dispatcher.stop_pipeline()
    except KeyboardInterrupt:
        logging.warning("You terminated execution.")
        exit(2)
    except BaseException as ex:
        logging.exception(ex)
        exit(1)
示例#5
0
    # clear
    if resp.status_code == 200 and app.logger.level != logging.DEBUG:
        clean_data(submission_id)
    # copy to another place
    else:
        backup_data(submission_id)
    return True


# setup dispatcher
DISPATCHER_CONFIG = os.environ.get(
    'DISPATCHER_CONFIG',
    '.config/dispatcher.json',
)
DISPATCHER = Dispatcher(
    dispatcher_config=DISPATCHER_CONFIG,
    on_complete=recieve_result,
)
DISPATCHER.start()


@app.route('/<submission_id>', methods=['POST'])
def submit(submission_id):
    token = request.values['token']
    if not secrets.compare_digest(token, SANDBOX_TOKEN):
        app.logger.debug(f'get invalid token: {token}')
        return 'invalid token', 403
    # make submission directory
    submission_dir = SUBMISSION_DIR / submission_id
    submission_dir.mkdir()
    # save attachments
    atts = request.files.getlist('attachments')
示例#6
0
文件: app.py 项目: Normal-OJ/Sandbox
    os.getenv(
        'SUBMISSION_BACKUP_DIR',
        'submissions.bk',
    ))
# check
if SUBMISSION_DIR == SUBMISSION_BACKUP_DIR:
    logger.error('use the same dir for submission and backup!')
# create directory
SUBMISSION_DIR.mkdir(exist_ok=True)
SUBMISSION_BACKUP_DIR.mkdir(exist_ok=True)
# setup dispatcher
DISPATCHER_CONFIG = os.getenv(
    'DISPATCHER_CONFIG',
    '.config/dispatcher.json.example',
)
DISPATCHER = Dispatcher(DISPATCHER_CONFIG)
DISPATCHER.start()


@app.post('/submit/<submission_id>')
def submit(submission_id: str):
    token = request.values['token']
    if not secrets.compare_digest(token, SANDBOX_TOKEN):
        logger.debug(f'get invalid token: {token}')
        return 'invalid token', 403
    # Ensure the testdata is up to data
    problem_id = request.form.get('problem_id', type=int)
    ensure_testdata(problem_id)
    language = Language(request.form.get('language', type=int))
    try:
        file_manager.extract(
示例#7
0
import asyncio
from dispatcher.dispatcher import Dispatcher
from dispatcher.redis_storage import RedisStorage
from .stats_storage import RedisStatsStorage
import settings

loop = asyncio.get_event_loop()
d_storage = RedisStorage(conn_address=settings.REDIS_ADDRESS, key_prefix=settings.APP_REDIS_PREFIX, loop=loop)
s_storage = RedisStatsStorage(conn_address=settings.REDIS_ADDRESS, key_prefix=settings.APP_REDIS_PREFIX, loop=loop)
dp = Dispatcher(loop=loop, storage=d_storage, stats_storage=s_storage)