google app engine - cron job throwing DeadlineExceededError -
i working on google cloud project in free trial mode. have cron job fetch data data vendor , store in data store. wrote code fetch data couple of weeks ago , working fine of sudden , started receiving error "deadlineexceedederror: overall deadline responding http request exceeded" last 2 days. believe cron job supposed timeout after 60 minutes idea why getting error?.
cron task
def run(): try: config = cron.config actual_data_source = config['xxx']['xxxx'] original_data_source = actual_data_source company_list = cron.rest_client.load(config, "companies", '') if not company_list: logging.info("company list empty") return "ok" row in company_list: company_repository.save(row,original_data_source, actual_data_source) return "ok"
repository code
def save( dto, org_ds , act_dp): try: key = 'fin/%s' % (dto['ticker']) company = companyinfo(id=key) company.stock_code = key company.ticker = dto['ticker'] company.name = dto['name'] company.original_data_source = org_ds company.actual_data_provider = act_dp company.put() return company except exception: logging.exception("company_repository: error occurred saving company record ") raise
restclient
def load(config, resource, filter): try: username = config['xxxx']['xxxx'] password = config['xxxx']['xxxx'] headers = {"authorization": "basic %s" % base64.b64encode(username + ":" + password)} if filter: from_date = filter['from'] to_date = filter['to'] ticker = filter['ticker'] start_date = datetime.strptime(from_date, '%y%m%d').strftime("%y-%m-%d") end_date = datetime.strptime(to_date, '%y%m%d').strftime("%y-%m-%d") current_page = 1 data = [] while true: if (filter): url = config['xxxx']["endpoints"][resource] % (ticker, current_page, start_date, end_date) else: url = config['xxxx']["endpoints"][resource] % (current_page) response = urlfetch.fetch( url=url, deadline=60, method=urlfetch.get, headers=headers, follow_redirects=false, ) if response.status_code != 200: logging.error("xxxx received status code %d!" % (response.status_code)) logging.error("error happend url: %s headers %s", url, headers) return 'sorry, xxxx api request failed', 500 db = json.loads(response.content) if not db['data']: break data.extend(db['data']) if db['total_pages'] == current_page: break current_page += 1 return data except exception: logging.exception("error occured xxxx api request") raise
i'm guessing same question this, more code: deadlineexceedederror: overall deadline responding http request exceeded
i modified code write database after each urlfetch. if there more pages, relaunches in deferred task, should before 10 minute timeout.
uncaught exceptions in deferred task cause retry, mindful of that.
it unclear me how actual_data_source
& original_data_source
worked, think should able modify part.
crontask
def run(current_page=0): try: config = cron.config actual_data_source = config['xxx']['xxxx'] original_data_source = actual_data_source data, more = cron.rest_client.load(config, "companies", '', current_page) row in data: company_repository.save(row, original_data_source, actual_data_source) # fetch rest if more: deferred.defer(run, current_page + 1) except exception e: logging.exception("run() experienced error: %s" % e)
restclient
def load(config, resource, filter, current_page): try: username = config['xxxx']['xxxx'] password = config['xxxx']['xxxx'] headers = {"authorization": "basic %s" % base64.b64encode(username + ":" + password)} if filter: from_date = filter['from'] to_date = filter['to'] ticker = filter['ticker'] start_date = datetime.strptime(from_date, '%y%m%d').strftime("%y-%m-%d") end_date = datetime.strptime(to_date, '%y%m%d').strftime("%y-%m-%d") url = config['xxxx']["endpoints"][resource] % (ticker, current_page, start_date, end_date) else: url = config['xxxx']["endpoints"][resource] % (current_page) response = urlfetch.fetch( url=url, deadline=60, method=urlfetch.get, headers=headers, follow_redirects=false, ) if response.status_code != 200: logging.error("xxxx received status code %d!" % (response.status_code)) logging.error("error happend url: %s headers %s", url, headers) return [], false db = json.loads(response.content) return db['data'], (db['total_pages'] != current_page) except exception e: logging.exception("error occured xxxx api request: %s" % e) return [], false
Comments
Post a Comment