async def run_loop(context, creds_key="credentials"): """Split this out of the async_main while loop for easier testing. """ loop = asyncio.get_event_loop() await update_poll_task_urls( context, context.queue.pollTaskUrls, args=(context.config['provisioner_id'], context.config['worker_type']), ) for poll_url, delete_url in get_azure_urls(context): try: claim_task_defn = await find_task(context, poll_url, delete_url, retry_request) except ScriptWorkerException: await asyncio.sleep(context.config['poll_interval']) break if claim_task_defn: log.info("Going to run task!") context.claim_task = claim_task_defn loop.create_task(reclaim_task(context)) running_task = loop.create_task(run_task(context)) status = await running_task await upload_artifacts(context) await complete_task(context, running_task.result()) cleanup(context) await asyncio.sleep(1) return status else: await asyncio.sleep(context.config['poll_interval']) if arrow.utcnow().timestamp - context.credentials_timestamp > context.config['credential_update_interval']: credentials = read_worker_creds(key=creds_key) if credentials and credentials != context.credentials: context.credentials = credentials
async def run_loop(context, creds_key="credentials"): """Split this out of the async_main while loop for easier testing. """ loop = asyncio.get_event_loop() await update_poll_task_urls( context, context.queue.pollTaskUrls, args=(context.config['provisioner_id'], context.config['worker_type']), ) for poll_url, delete_url in get_azure_urls(context): try: claim_task_defn = await find_task(context, poll_url, delete_url, retry_request) except ScriptWorkerException: await asyncio.sleep(context.config['poll_interval']) break if claim_task_defn: log.info("Going to run task!") context.claim_task = claim_task_defn loop.create_task(reclaim_task(context)) running_task = loop.create_task(run_task(context)) status = await running_task await upload_artifacts(context) await complete_task(context, running_task.result()) cleanup(context) await asyncio.sleep(1) return status else: await asyncio.sleep(context.config['poll_interval']) if arrow.utcnow( ).timestamp - context.credentials_timestamp > context.config[ 'credential_update_interval']: credentials = read_worker_creds(key=creds_key) if credentials and credentials != context.credentials: context.credentials = credentials
async def run_loop(context, creds_key="credentials"): """Split this out of the async_main while loop for easier testing. args: context (scriptworker.context.Context): the scriptworker context. creds_key (str, optional): when reading the creds file, this dict key corresponds to the credentials value we want to use. Defaults to "credentials". Returns: int: status """ loop = asyncio.get_event_loop() await update_poll_task_urls( context, context.queue.pollTaskUrls, args=(context.config['provisioner_id'], context.config['worker_type']), ) for poll_url, delete_url in get_azure_urls(context): try: claim_task_defn = await find_task(context, poll_url, delete_url, retry_request) except ScriptWorkerException: await asyncio.sleep(context.config['poll_interval']) break if claim_task_defn: log.info("Going to run task!") status = 0 context.claim_task = claim_task_defn loop.create_task(reclaim_task(context, context.task)) try: # TODO download and verify chain of trust artifacts if # context.config['verify_chain_of_trust'] # write an audit logfile to task_log_dir; copy cot into # artifact_dir/cot ? status = await run_task(context) generate_cot(context) except ScriptWorkerException as e: status = worst_level(status, e.exit_code) log.error("Hit ScriptWorkerException: {}".format(str(e))) try: await upload_artifacts(context) except ScriptWorkerException as e: status = worst_level(status, e.exit_code) log.error("Hit ScriptWorkerException: {}".format(str(e))) await complete_task(context, status) cleanup(context) await asyncio.sleep(1) return status else: await asyncio.sleep(context.config['poll_interval']) if arrow.utcnow().timestamp - context.credentials_timestamp > context.config['credential_update_interval']: # pragma: no branch credentials = read_worker_creds(key=creds_key) if credentials and credentials != context.credentials: context.credentials = credentials
async def run_loop(context, creds_key="credentials"): """Split this out of the async_main while loop for easier testing. args: context (scriptworker.context.Context): the scriptworker context. creds_key (str, optional): when reading the creds file, this dict key corresponds to the credentials value we want to use. Defaults to "credentials". Returns: int: status """ loop = asyncio.get_event_loop() await update_poll_task_urls( context, context.queue.pollTaskUrls, args=(context.config['provisioner_id'], context.config['worker_type']), ) for poll_url, delete_url in get_azure_urls(context): try: claim_task_defn = await find_task(context, poll_url, delete_url, retry_request) except ScriptWorkerException: await asyncio.sleep(context.config['poll_interval']) break if claim_task_defn: log.info("Going to run task!") status = 0 context.claim_task = claim_task_defn loop.create_task(reclaim_task(context, context.task)) try: if context.config['verify_chain_of_trust']: chain = ChainOfTrust(context, context.config['cot_job_type']) await verify_chain_of_trust(chain) status = await run_task(context) generate_cot(context) except ScriptWorkerException as e: status = worst_level(status, e.exit_code) log.error("Hit ScriptWorkerException: {}".format(e)) try: await upload_artifacts(context) except ScriptWorkerException as e: status = worst_level(status, e.exit_code) log.error("Hit ScriptWorkerException: {}".format(e)) except aiohttp.ClientError as e: status = worst_level(status, STATUSES['intermittent-task']) log.error("Hit aiohttp error: {}".format(e)) await complete_task(context, status) cleanup(context) await asyncio.sleep(1) return status else: await asyncio.sleep(context.config['poll_interval'])
def test_get_azure_urls(context): count = 0 for poll_url, delete_url in poll.get_azure_urls(context): assert poll_url == "poll{}".format(count) assert delete_url == "delete{}".format(count) count += 1
def test_get_azure_urls(self, context): count = 0 for poll_url, delete_url in poll.get_azure_urls(context): assert poll_url == "poll{}".format(count) assert delete_url == "delete{}".format(count) count += 1