我有一个无法开始工作的 TimerTrigger Azure 函数(在 Docker 容器中运行)。执行__init__.py
,引入一些自定义模块,抓取互联网(使用 selenium),并输出到 Twitter。在本地,所有代码都有效。在本地打包到 Azure Function Docker 容器中时,我得到了 zilch。
下面,我放了function.json
文件,我认为这是我的问题所在。我想我可能需要更多的组件,而不仅仅是 TimerTrigger 部分。互联网上没有关于基于 python 的 Azure Functions 和 TimerTriggers 的优秀文档,超出了微软发布的内容(相信我,我已经彻底阅读了这些文章中的每一篇)。
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 * * * * *",
"authLevel": "anonymous"
}
]
}
我的开始__init__.py
(我基本上把我所有的自定义模块等放在启动函数时自动创建的函数中):
def main(mytimer: func.TimerRequest) -> None: #should be something else?
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
if mytimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function ran at %s', utc_timestamp)
# Class instantiation for the handling stuff ----
name_handle_instance = dc.NameHandle()
#calls other functions below...
如果 Dockerfile 是相关的:
FROM mcr.microsoft.com/azure-functions/python:3.0-python3.6-appservice
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
# install python dependencies
RUN apt-get update \
&& apt-get install -y \
build-essential \
cmake \
git \
wget \
unzip \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install --upgrade pip
RUN pip3 install --upgrade setuptools
# chrome install
ARG CHROME_VERSION="google-chrome-stable"
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update -qqy \
&& apt-get -qqy install \
${CHROME_VERSION:-google-chrome-stable} \
&& rm /etc/apt/sources.list.d/google-chrome.list \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
# install chromedriver used by Selenium
RUN LATEST=$(wget -q -O - http://chromedriver.storage.googleapis.com/LATEST_RELEASE) && \
wget http://chromedriver.storage.googleapis.com/$LATEST/chromedriver_linux64.zip && \
unzip chromedriver_linux64.zip && ln -s /chromedriver /usr/local/bin/chromedriver
ENV PATH="/usr/local/bin/chromedriver:${PATH}"
RUN pip install -U selenium
COPY . /home/site/wwwroot
RUN cd /home/site/wwwroot && \
pip install -r requirements.txt