1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

database maintenance function

This commit is contained in:
Kyle Spearrin 2017-11-15 07:59:03 -05:00
parent 651e42b45c
commit c0cce5a466
2 changed files with 40 additions and 3 deletions

View File

@ -0,0 +1,39 @@
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
namespace Bit.Function
{
public static class DatabaseMaintenance
{
[FunctionName("DatabaseMaintenance")]
public static void Run([TimerTrigger("0 0 * * *")]TimerInfo myTimer, TraceWriter log)
{
var connectionString = ConfigurationManager.ConnectionStrings["vault_db"].ConnectionString;
using(var connection = new SqlConnection(connectionString))
{
connection.Open();
// ref: http://bit.ly/2zFNcZo
var cmd = new SqlCommand("[dbo].[AzureSQLMaintenance]", connection)
{
CommandType = CommandType.StoredProcedure
};
// Options: "all", "index", "statistics"
cmd.Parameters.Add("@operation", SqlDbType.NVarChar).Value = "all";
// Options: "smart", "dummy"
cmd.Parameters.Add("@mode", SqlDbType.NVarChar).Value = "smart";
// Options: 0, 1
cmd.Parameters.Add("@LogToTable", SqlDbType.Bit).Value = 1;
// Asynchronous BeginExecuteNonQuery for this long running sproc to avoid timeouts
var result = cmd.BeginExecuteNonQuery();
cmd.EndExecuteNonQuery(result);
}
}
}
}

View File

@ -7,9 +7,7 @@ namespace Bit.Function
public static class KeepAlive
{
[FunctionName("KeepAlive")]
public static void Run(
[TimerTrigger("0 */15 * * * *")]TimerInfo myTimer,
TraceWriter log)
public static void Run([TimerTrigger("0 */15 * * * *")]TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
}