https://github.com/jmbl1685/azure-functions-sql
This sample uses Azure Functions (Timer Trigger)
https://github.com/jmbl1685/azure-functions-sql
azure-functions csharp
Last synced: 10 months ago
JSON representation
This sample uses Azure Functions (Timer Trigger)
- Host: GitHub
- URL: https://github.com/jmbl1685/azure-functions-sql
- Owner: jmbl1685
- Created: 2018-08-16T19:13:31.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-16T22:51:40.000Z (almost 8 years ago)
- Last Synced: 2025-06-08T13:42:09.014Z (about 1 year ago)
- Topics: azure-functions, csharp
- Language: C#
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Azure Function (Timer Trigger)
El siguiente proceso es un ejemplo muy básico que corresponse a una Azure Function tipo TimerTrigger que se estará ejecutando cada 5 minutos
y como caso de prueba hará incremento de 1 dia a la fecha correspondiente del campo LimitValidateAt si y solo si el esado sea 1 y las fechas coincidan con la actual.
```c#
// Formato de fecha CRON --> "0 */5 * * * *" 5 MINUTOS
[FunctionName("AddOneDayLimitValidateAt_Example")]
public static async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log)
{
var DBConnectionString = ConfigurationManager.
ConnectionStrings["sqlserver_azure"].ConnectionString;
using (SqlConnection connection = new SqlConnection(DBConnectionString))
{
connection.Open();
var query = @"
UPDATE [dbo].[Users]
SET LimitValidateAt = DATEADD(DAY, 1, LimitValidateAt)
WHERE CONCAT(YEAR(CreateAt),'-',MONTH(CreateAt)) = CONCAT(YEAR(GETDATE()), '-', MONTH(GETDATE()))
AND Status = 1";
using(SqlCommand cmd = new SqlCommand(query, connection))
{
var rows = await cmd.ExecuteNonQueryAsync();
log.Info($"{rows} rows has been updated");
}
}
}
```