Where can I see the next time the function starts? - python-3.x

I have a function in Azure on Python that runs every 12 hours:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 0 */12 * * *"
}
]
}
Is there any way to see when the next launch will be made?

I'm not sure if there is a way to see the trigger time directly, but since your time trigger is every 12 hours, so we can get to know the next trigger time indirectly by the request history in "Monitor" of the function.
In the "Monitor" tag (here in the screenshot above, I deployed a time trigger function triggered every minute), we can see the running history of the function, since we can see the last running time, so we can also know the next trigger time(the last time +12hours).
By the way, if we want to use the monitor, we need to enable application insights when we create the function app.
Hope it would be helpful to your question~
Update:
We can also see the time of next launch in "Live Metrics Stream", shown as below:
click "Monitor" --> "Live app metrics"
we can find the next time in the message in "Sample Telemetry"

Related

Slow upload speed from Azure Function to a Container in a Storage Account

I'm experiencing a slower upload speed than I need to meet a project goals. We need to upload files up to 0.5GB from an AZ Function service to one of our storage accounts. This process is taking more time than we expect (>10min). Another issue that got our attention is the non-linearity of the relationship between file size and upload time. A 160MB file is taking 1.5min to upload but a 290MB exceeds 10min. Does anyone understand why this is happening? We didn't manage to figure it out through the community/docs.
My function.json file looks like this:
{
"scriptFile": "az_func.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 0 0 * * 2"
},
{
"name": "$return",
"type": "blob",
"path": "cvmdailyreports/test_func_json.csv",
"connection": "AzureWebJobsCVMDataStorageConn",
"direction": "out"
}
]
}
The az_func.py script just scrapes some data from a website, manipulates some data and returns a csv (this process doesn't take too long, so it is not the source of inneficiency).
Anyone knows if it is normal for AZ functions to take that long to upload files to AZ Storage Accounts or if there is a faster way to do it?
The az_func.py code is the following:
import datetime
import logging
import azure.functions as func
from src.data.import_data import import_daily_reports
from src.data.transform_data import transform_daily_reports
def main(mytimer: func.TimerRequest):
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)
csv = transform_daily_reports(import_daily_reports(n=8)).to_csv(index=False)
logging.info('The csv was created, sending to upload now.')
return csv
The transform and import functions are custom functions to import some data from a website and to concatenate that into a dataframe. As stated before, they run without a problem, as can be seen in the logs from the App Insights:
Invocation Details - Timeout Error Logs
The Function App is running on linux, with runtime version 4.0
We are currently using the Consumption plan, which has the 10 mins limitation for timeout, and I already configured the host.json file to have the max timeout possible.
Thanks!

Azure function runtime does not start

I have a set of Azure functions running in the Azure running over a year already shoveling a huge amounts of data and everything has been fine so far. Last code update was about 3 weeks old and since then again it's processed a lot of data. 2 days ago we suddenly noticed it just stopped working and the Azure function does not start at all. On my dev PC obviously everything works like charm.
Error message #1
I'm using DI in Azure function, I load assembly during function startup and register it to the IoC. The error message is, that the type is not assignable to the interface. Which was clearly nonsense as
a. It is
b. It's been working this way since forerer. Since I got really desperate I decided to do an experiment and I modified the code (essentially removing the interface), that would prevent the function runtime to throw this particular error and it was replaced by another.
Error message #2
So the Azure function runtime stopped complaining about object inheritance, but now it is displaying a different error message.
Microsoft.Azure.WebJobs.Extensions.DurableTask: Value cannot be null. (Parameter 'hostConfiguration').
I googled it like crazy, went through DurableTask documentation, but still no ideas. I can restart function, redeploy it, but nothing helps.
My host.json is:
{
"version": "2.0",
"functionTimeout": "00:15:00",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"maxTelemetryItemsPerSecond": 20,
"excludedTypes": "Request"
}
},
"console": {
"isEnabled": true
}
},
"extensions": {
"http": {
"routePrefix": ""
},
"durableTask": {
"hubName": "IngressFunctionHubVS"
}
}
}
Literally any idea why perfectly running Azure function (it literally ran for ~18 month and processed tenths of GBs of data) can suddenly stop working without any our intervention ( I checked the logs - no one touched it) will be highly appreciated.

Run an Azure Function Every 15 minutes

I have an Azure Function whose method looks like this:
[FunctionName("RunTask")]
public static async Task Run([TimerTrigger("0 */15 * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info("Running task...");
await Task.CompletedTask;
}
The above method is only a shell to test the timing abilities. I want the function to run every 15 minutes. However, the task seems to only run on the first pass. I'm basing this on what I see in the Azure Portal. In the Azure Portal, I select the RunTask function to view the Logs. This lets me watch the trace logs in real time.
The first log appears correctly. However, I do not see any additional logs written. Instead, I see "No new trace in the past [x] min(s)."
Oddly, if I change the timer from 15 minutes to 5 minutes ([TimerTrigger("0 */15 * * * *")] to [TimerTrigger("0 */5 * * * *")]), it works as expected. Why is that? How do I setup my function to run every 15 minutes?
Please note, I have to use the Microsoft.NET.Sdk.Functions-1.0.24 implementation.
Thank you!
There is no problem with the timer trigger. Your function is triggered every 15 minutes successfully, but the log window is fragile. It sometimes will not show the logs after a few minutes, so when you set the timer from 15 to 5 minutes it shows the logs normally.
For this problem, you can see the logs of your function by following the steps below:
Go to "kudu" of your function app.
Then click "Debug console" --> "CMD" --> "LogFiles" --> "Application" --> "Functions" --> "function", choose your function, click the edit pencil, then you can see the logs.

VSCode stops on invisible breakpoint on "async_hooks.js" while debugging a node.js script

so I built a script in node.js which supposed to take csv files, parse them and enter them to DB.
Sometimes, when I debug my code, it stops on like an invisible breakpoint found in async_hooks.js file, on the first line of the "emitHookFactory" function (line 163).
The call stack states only one call- "emitBeforeNative" on the same file.
I noticed a few things on my trials:
I have 3 types of files I need to parse and put in the DB. It happens only on one of the file types, which is extremely large (3.1m~ lines on csv, while the others have 50~200K lines). I tried to load it partially- only the starting 20K lines (copied them to a new file, no changes in code) and it didn't break. which means the size has to do with the debugger stopping?
I tried to reproduce it with other means but no success. Also, it doesn't happen always (even when ran on the same file)- but like 80-85% of the times.
My script goes like this: query DB and AWS to find a new file > download file to local > stream the file from local > on line event- parse line and perform data manipulations > on end event - loop through all manipulated data, build queries and query the DB to insert it. I've put a few breakpoints on key places and found out the breakpoint SEEMS to happen somewhere in the middle of emitting the line events. The callback function is a normal function, not async, and there are no async operations inside. In fact, there are only array and string manipulations operations inside- not even 3rd party operation or anything unusual.
I tried to look at the internet for solution. Didn't find any clear way to comletely get rid of it, only workaround which I didn't really understand (kinda new to JS environments so I could not get the concepts of how can I disable or ignore it...)
Thanks for the help in advanced.
Based on https://github.com/nodejs/node/issues/15464
There's a way to ignore stepping into Node guts. In your launch.json add the following skipFiles directive:
"skipFiles": [
"<node_internals>/**"
]
or you can ignore particularly /internal/async_hooks with this:
"skipFiles": [
"<node_internals>/internal/async_hooks.js",
"<node_internals>/internal/inspector_async_hook.js"
]
After all, your config may look like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Debug",
"runtimeExecutable": "<your executable path>",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"timeout": 30000,
"skipFiles": [
"<node_internals>/**"
]
}
]
}
This also might be related to a known NodeJS bug: https://github.com/nodejs/node/issues/36022
Could you please try whether our new JavaScript debugger still has this problem. For details see the release notes of VS Code 1.42: https://code.visualstudio.com/updates/v1_42#_new-javascript-debugger.

Running setTimeout and showing log in terminal

I am trying to show the the log using below code in the terminal, but it is only showing one time, what is the wrong in the code ?
I created a file time.js with below code
setTimeout(function() { console.log("setTimeout: It's been one second!"); }, 1000);
and running the code in terminal like this
node time.js
the output is given below
Apples-MacBook-Pro:s3 apple$ node time.js
setTimeout: It's been one second!
Apples-MacBook-Pro:s3 apple$
while I am expecting setTimeout: It's been one second! log every minute
You should use the setInterval method instead:
setInterval(function() { console.log("setInterval: It's been one second!"); }, 1000);
However, beware that this code is dependent on the event loopback and if you have code that occupies the event loopback for too long, this code may not execute every second as you ideally want it to.

Resources