from flask import Blueprint, make_response from frestq.tasks import SimpleTask from frestq.app import app # set database uri import os ROOT_PATH = os.path.split(os.path.abspath(__file__))[0] SQLALCHEMY_DATABASE_URI = 'sqlite:///%s/db.sqlite' % ROOT_PATH say_api = Blueprint('say', __name__) @say_api.route('/hello/<username>', methods=['POST']) def post_hello(username): task = SimpleTask( receiver_url='http://127.0.0.1:5001/api/queues', action="hello_world", queue="say_queue", data={ 'username': username } ) task.create_and_send() return make_response("", 200) app.register_blueprint(say_api, url_prefix='/say') app.configure_app(config_object=__name__) if __name__ == "__main__": app.run(parse_args=True)
import os ROOT_PATH = os.path.split(os.path.abspath(__file__))[0] SQLALCHEMY_DATABASE_URI = 'sqlite:///%s/db.sqlite' % ROOT_PATH ROOT_URL = 'https://127.0.0.1:5000/api/queues' SSL_CERT_PATH = '%s/certs/selfsigned/cert.pem' % ROOT_PATH SSL_KEY_PATH = '%s/certs/selfsigned/key-nopass.pem' % ROOT_PATH ALLOW_ONLY_SSL_CONNECTIONS = True say_api = Blueprint('say', __name__) @say_api.route('/hello/<username>', methods=['GET', 'POST']) def post_hello(username): task = SimpleTask(receiver_url='https://127.0.0.1:5001/api/queues', action="hello_world", queue="say_queue", data={'username': username}) task.create_and_send() return make_response("", 200) app.register_blueprint(say_api, url_prefix='/say') app.configure_app(config_object=__name__) if __name__ == "__main__": app.run(parse_args=True)
SERVER_PORT = 5001 ROOT_URL = 'http://127.0.0.1:5001/api/queues' # action handler: @decorators.task(action="hello_world", queue="say_queue") def hello_world(task): approve_task = ExternalTask(data=dict(type="approve")) task.add(approve_task) return dict(output_data=None) approve_api = Blueprint('approve', __name__) @approve_api.route('/<task_id>', methods=['POST']) def approve(task_id): task = ExternalTask.instance_by_id(task_id) task.finish(data=dict(yeah="whatever")) return make_response("", 200) app.register_blueprint(approve_api, url_prefix='/approve') app.configure_app(config_object=__name__) if __name__ == "__main__": app.run(parse_args=True)
from public_api import public_api from taskqueue import start_queue def extra_parse_args(self, parser): parser.add_argument("--reset-tally", help="Enable making a second tally for :election_id", type=int) def extra_run(self): if self.pargs.reset_tally and isinstance(self.pargs.reset_tally,(int,long)): election_id = self.pargs.reset_tally tally_election.performer_jobs.reset_tally(election_id) return True return False if __name__ == "__main__": app.configure_app(scheduler=False, config_object=__name__) app.register_blueprint(public_api, url_prefix='/public_api') if len(sys.argv) == 3 and sys.argv[1] == "create-tarball": from tools import create_tarball create_tarball.create(sys.argv[2]) exit(0) app.run(parse_args=True, extra_parse_func=extra_parse_args, extra_run=extra_run) else: app.configure_app(config_object=__name__) app.register_blueprint(public_api, url_prefix='/public_api') start_queue()
SERVER_NAME = '127.0.0.1:5001' SERVER_PORT = 5001 ROOT_URL = 'http://127.0.0.1:5001/api/queues' # action handler: @decorators.task(action="hello_world", queue="say_queue") def hello_world(task): approve_task = ExternalTask(data=dict(type="approve")) task.add(approve_task) return dict( output_data = None ) approve_api = Blueprint('approve', __name__) @approve_api.route('/<task_id>', methods=['POST']) def approve(task_id): task = ExternalTask.instance_by_id(task_id) task.finish(data=dict(yeah="whatever")) return make_response("", 200) app.register_blueprint(approve_api, url_prefix='/approve') app.configure_app(config_object=__name__) if __name__ == "__main__": app.run(parse_args=True)