Netlify: Scheduled Function trigger does not show in Deploy log - netlify

I have deployed the recently introduced Scheduled Functions feature available from netlify labs for a site. I wish to have netlify execute the npm run generate script (its a Nuxt project) every day once.
The functions tab even shows the function as below:
test-scheduled-functionScheduled
Created on Jun 21 (19 hours ago)
Next execution on Jun 23 at 5:30 AM
The function itself is a standard daily function
const { schedule } = require('#netlify/functions')
const handler = async function(event, context) {
console.log("Received event:", event)
return {
statusCode: 200,
};
};
module.exports.handler = schedule("#daily", handler);
Even though the functions scheduler shows a date and time, I find that the deployment logs do not show a fresh deployment at the appointed time.
Is my understanding of scheduled functions wrong or is there something else that needs to be done to run the deployment function on a daily basis
Thanks

Related

Why are my Azure triggered WebJobs never run successfully?

I have a few Azure WebJobs that run to completion, once my business logic is done I call await StopAsync(stoppingToken);
However, Azure Portal continues to show their status as "Running" until eventually the jobs terminated after the default 120 second timeout.
How can I correctly tell Azure Portal/Kudu that the job is in fact finished?
Here is an example that shows the issue:
namespace MyService
{
public class MyService : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
// same issue whether or not I call this:
await StopAsync(stoppingToken);
}
}
}
A week after posting this question my jobs are now mysteriously completing successfully even though no changes were made, I assume someone at Microsoft fixed something on their end.

Trying to execute my code every 12hours on the AWS lambda server

I have to run my code every 12 hours. I wrote the following code, and I deployed it to AWS Lambda for the code to run every 12 hours. However, I see that the code does not run every 12 hours. Could you guys help me with this?
nodeCron.schedule("0 */12 * * *", async () => {
let ids = ["5292865", "2676271", "5315840"];
let filternames = ["Sales", "Engineering", ""];
await initiateProcess(ids[0], filternames[0]);
await initiateProcess(ids[1], filternames[1]);
await initiateProcess(ids[2], filternames[2]);
});
AWS Lambda is an event-driven service. It runs your code in response to events. AWS Lambda functions can be configured to run up to 15 minutes per execution. They cannot run longer than that.
I would suggest you use Amazon EventBridge to trigger your Lambda function to run on a 12-hour schedule:
Create a Rule with a schedule to run every 12 hours
In this Rule, create a Target, which is your Lambda function.
Then, you will be able to see if it was executed properly or not, and Lambda logs will be available in CloudWatch Logs.

Azure Web Job always Failed

I have this Azure WebJob function that runs every Saturday. But the Azure function always tagged as Failed but the Job runs successfully when finished as I checked the log.
Already increase WEBJOBS_IDLE_TIMEOUT and SCM_COMMAND_IDLE_TIMEOUT in Configuration but still tagged as Failed. But still got this error.
Command 'cmd /c ""Software.. ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.
The number of data to be processed is unpredictable, it depends the number of users inputted the values, so the processing time would be between 1 to 40 minutes, 1 minute for least data and 40 minutes for larger data.
I'm currently using the latest version of WebJob SDK.
Here's the code snippet.
public class ProcessDataFunction
{
private readonly IProcessData _processData;
public ProcessDataFunction(IProcessData processData)
{
_processData = processData;
}
[Singleton]
public async Task ProcessDataMessage([TimerTrigger("0 0 12 * * 6", RunOnStartup = true)] TimerInfo myTimer, ILogger logger, CancellationToken cancellationToken)
{
logger.LogInformation("Long running Job Started...");
var dateSync = DateTimeOffset.UtcNow;
await _processData.ProcessAsync(cancellationToken, dateSync);
logger.LogInformation("Long running Job Finished...");
}
}
class Program
{
static async Task Main()
{
var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
b.AddTimers();
b.AddAzureStorageCoreServices();
});
builder.ConfigureLogging((context, b) =>
{
b.AddConsole();
});
builder.ConfigureServices((context, services) =>
{
services.ConfigureHttpClients(context.Configuration)
.ConfigureDataProcessor()
.ConfigureDbContext(context.Configuration);
});
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
}
Thanks! Just to confirm if you have enabled Always on setting? As mentioned in the document:
“A web app can time out after 20 minutes of inactivity, and only requests to the actual web app can reset the timer. Viewing the app's configuration in the Azure portal or making requests to the advanced tools site (https://<app_name>.scm.azurewebsites.net) doesn't reset the timer. If you set your web app to run continuously, run on a schedule, or use event-driven triggers, enable the Always on setting on your web app's Azure Configuration page. The Always on setting helps to make sure that these kinds of WebJobs run reliably. This feature is available only in the Basic, Standard, and Premium pricing tiers. “
Also suggest you for triggered jobs in your Program.cs,
try to replace
host.Run(); by host.Start();
Further you may also refer to this blog might helps.

Why does my Time trigger webjob keep running?

I have a Webjob that I want to be time triggered:
public class ArchiveFunctions
{
private readonly IOrderArchiver _orderArchiver;
public ArchiveFunctions(IOrderArchiver orderArchiver)
{
_orderArchiver = orderArchiver;
}
public async Task Archive([TimerTrigger("0 */5 * * * *")] TimerInfo timer, TextWriter log)
{
log.WriteLine("Hello world");
}
}
My program.cs:
public static void Main()
{
var config = new JobHostConfiguration
{
JobActivator = new AutofacJobActivator(RegisterComponents())
};
config.UseTimers();
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
my publish-setting.json:
{
"$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
"webJobName": "OrdersArchiving",
"runMode": "OnDemand"
}
Here is what it looks like on azure portal:
My problem is that the job runs, I have the hello world, but the job keeps in run state and it get to a time out error message:
[02/05/2018 15:34:05 > f0ea5f: ERR ] Command 'cmd /c ""Ores.Contr ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.
What can I do to fix this?
I have a wild guess RunAndBlock could be a problem.. but I do not see a solution..
Thanks!
Edit:
I have tested Rob Reagan answer, it does help with the error, thank you!
On my same service, I have one other time triggerd job (was done in core, while mine is not).
You can see the Webjob.Missions is 'triggered', and status update on last time it ran. You can see as well the schedule on it.
I would like to have the same for mine 'OrdersArchiving'.
How can I achieve that?
Thanks!
Change your run mode to continuous and not triggered. The TimerTrigger will handle executing the method you've placed it on.
Also, make sure that you're not using a Free tier for hosting your WebJob. After twenty minutes of inactivity, the app will be paused and will await a new HTTP request to wake it up.
Also, make sure you've enabled Always On on your Web App settings to prevent the same thing from happening to a higher service tier web app.
Edit
Tom asked how to invoke methods on a schedule for a Triggered WebJob. There are two options to do so:
Set the job up as triggered and use a settings.json file to set up the schedule. You can read about it here.
Invoke a method via HTTP using an Azure Scheduler. The Azure Scheduler is a separate Azure service that you can provision. It has a free tier which may be sufficient for your use. Please see David Ebbo's post on this here.

Thawing Lambda functions doesn't decrease latency

I'm using serverless-warmup-plugin to run a cron that invokes a Lambda function every 10 minutes. The code for the Lambda function looks like this:
exports.lambda = (event, context, callback) => {
if (event.source === 'serverless-plugin-warmup') {
console.log('Thawing lambda...')
callback(null, 'Lambda is warm!')
} else {
// ... logic for the lambda function
}
}
This works on paper but in practice the cron doesn't keep the Lambda function warm even though it successfully invokes it every 10 minutes.
When the Lambda is invoked via a different event source (other than the cron) it takes around 2-3 seconds for the code to execute. Once it's executed this way, Lambda actually warms up and starts responding under 400ms. And it stays warm for a while.
What am I missing here?
As the official documentation states:
Note
When you write your Lambda function code, do not assume that AWS Lambda always reuses the container because AWS Lambda may choose not to reuse the container. Depending on various other factors, AWS Lambda may simply create a new container instead of reusing an existing container.
It seems like a "bad architecture design" to try to keep a Lambda Container up, but, apparently it's a normal scenario your warmed container not being used when a different event source triggers a new container.

Resources