def rq_worker(): """Start an rq worker in the context of dallinger.""" setup_experiment(log) with Connection(db.redis_conn): # right now we care about low queue for bots worker = Worker("low") worker.work()
def test_bot_factory(self): from dallinger.command_line import bot_factory from dallinger.deployment import setup_experiment from dallinger.bots import BotBase setup_experiment(log=mock.Mock()) bot = bot_factory("some url") assert isinstance(bot, BotBase)
def setup(self): """Override setup to be able to build the experiment directory without a working postgresql (it will work inside the docker compose env). Maybe the postgres check can be removed altogether? """ self.exp_id, self.tmp_dir = setup_experiment( self.out.log, exp_config=self.exp_config, local_checks=False, )
def config(self): from dallinger.deployment import setup_experiment cwd = os.getcwd() config = get_config() if not config.ready: config.load() (id, tmp) = setup_experiment(log=mock.Mock(), verbose=True, exp_config={}) os.chdir(tmp) yield config os.chdir(cwd)
def bot(app, debug): """Run the experiment bot.""" if debug is None: verify_id(None, None, app) (id, tmp) = setup_experiment(log) if debug: url = debug else: heroku_app = HerokuApp(dallinger_uid=app) worker = generate_random_id() hit = generate_random_id() assignment = generate_random_id() ad_url = "{}/ad".format(heroku_app.url) ad_parameters = "assignmentId={}&hitId={}&workerId={}&mode=sandbox" ad_parameters = ad_parameters.format(assignment, hit, worker) url = "{}?{}".format(ad_url, ad_parameters) bot = bot_factory(url) bot.run_experiment()
def wrapper(*args, **kwargs): # pragma: no cover from dallinger.docker.tools import build_image from dallinger.command_line.docker import push import docker config = get_config() config.load() image_name = config.get("docker_image_name", None) if image_name: client = docker.from_env() try: check_output(["docker", "manifest", "inspect", image_name]) print(f"Image {image_name} found on remote registry") return f(*args, **kwargs) except CalledProcessError: # The image is not on the registry. Check if it's available locally # and push it if it is. If images.get succeeds it means the image is available locally print( f"Image {image_name} not found on remote registry. Trying to push" ) raw_result = client.images.push(image_name) # This is brittle, but it's an edge case not worth more effort if not json.loads(raw_result.split("\r\n")[-2]).get("error"): print(f"Image {image_name} pushed to remote registry") return f(*args, **kwargs) # The image is not available, neither locally nor on the remote registry print( f"Could not find image {image_name} specified in experiment config as `docker_image_name`" ) raise click.Abort _, tmp_dir = setup_experiment(Output().log, exp_config=config.as_dict(), local_checks=False) build_image(tmp_dir, config.get("docker_image_base_name"), out=Output()) pushed_image = push.callback(use_existing=True) add_image_name(LOCAL_CONFIG, pushed_image) return f(*args, **kwargs)