반응형
자동 트리거 없이 zure 웹 작업을 연속적으로 실행하고 public static 함수를 호출하는 방법
저는 지속적으로 실행되어야 하는 azure web job을 개발하고 있습니다.저는 공공 정적 기능을 가지고 있습니다.나는 이 기능이 대기열 없이 자동으로 트리거되기를 원합니다.지금은 계속 실행하는 동안(true)을 사용하고 있습니다.이것을 할 수 있는 다른 방법이 있습니까?
제 코드 아래를 찾아주세요.
static void Main()
{
var host = new JobHost();
host.Call(typeof(Functions).GetMethod("ProcessMethod"));
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
[NoAutomaticTriggerAttribute]
public static void ProcessMethod(TextWriter log)
{
while (true)
{
try
{
log.WriteLine("There are {0} pending requests", pendings.Count);
}
catch (Exception ex)
{
log.WriteLine("Error occurred in processing pending altapay requests. Error : {0}", ex.Message);
}
Thread.Sleep(TimeSpan.FromMinutes(3));
}
}
감사해요.
다음 단계를 통해 원하는 것을 얻을 수 있습니다.
- 비동기식으로 메서드 변경
- 잠들기를 기다리다
- 호스트를 사용합니다.호스트 대신 Async()를 호출합니다.호출()
아래 단계를 반영하여 코드를 변환했습니다.
static void Main()
{
var host = new JobHost();
host.CallAsync(typeof(Functions).GetMethod("ProcessMethod"));
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
[NoAutomaticTriggerAttribute]
public static async Task ProcessMethod(TextWriter log)
{
while (true)
{
try
{
log.WriteLine("There are {0} pending requests", pendings.Count);
}
catch (Exception ex)
{
log.WriteLine("Error occurred in processing pending altapay requests. Error : {0}", ex.Message);
}
await Task.Delay(TimeSpan.FromMinutes(3));
}
}
Microsoft를 사용합니다.애저, 웹잡스내선 번호.타이머는 https://github.com/Azure/azure-webjobs-sdk-extensions/blob/master/src/ExtensionsSample/Samples/TimerSamples.cs 을 참조하여 TimeSpan 또는 Crontab 명령을 사용하여 메서드를 실행하는 트리거를 만듭니다.
Microsoft 추가.애저, 웹잡스내선 번호.NuGet에서 프로젝트로 가는 타이머.
public static void ProcessMethod(TextWriter log)
된다
public static void ProcessMethod([TimerTrigger("00:05:00",RunOnStartup = true)] TimerInfo timerInfo, TextWriter log)
5분 동안 트리거(TimeSpan 문자열 사용)
Program.cs Main에서 타이머를 사용하도록 구성을 다음과 같이 설정해야 합니다.
static void Main()
{
JobHostConfiguration config = new JobHostConfiguration();
config.UseTimers();
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
언급URL : https://stackoverflow.com/questions/29625813/how-to-make-azure-webjob-run-continuously-and-call-the-public-static-function-wi
반응형
'source' 카테고리의 다른 글
몽고드와 몽고의 정확한 차이점은 무엇입니까? (0) | 2023.04.29 |
---|---|
Excel 시트에 PostgreSQL 쿼리 (0) | 2023.04.29 |
데이터 프레임 목록을 한 행씩 하나의 데이터 프레임으로 결합 (0) | 2023.04.24 |
작업 이름 "..getProjectMetadata"가 없습니다. (0) | 2023.04.24 |
정규식으로 파일 형식 검증 (0) | 2023.04.24 |