Giter VIP home page Giter VIP logo

schedfuncapps's Introduction

SchedFuncApps

以 Timer-Triggered 的 Azure Functions 作為 unix-style crontab 的排程器的概念驗證。

開發環境

  • .NET 6.0 SDK
  • Azure Functions Core Tools 4.x
  • Azure CLI 2.4.0 以上
  • Azurite

簡介

DemoApp 可以在本機測試或布屬到 Heroku。

FunctionApps 可以在本機測試或布屬到 Azure Functions。

DemoApp

用以展示 Timer-Triggered Function App 定期發送 Request 的紀錄。其中 FunctionControllerRenew 負責接收 SubscriptionRenewScheduler 的請求、Status 負責接收 SubscriptionStatusScheduler 的請求。

HomeControllerIndex 展示請求的紀錄、Reset 清空紀錄。

SubscriptionRenewScheduler

每 20 秒發送一次 HTTP POST 到 DemoApp。

我在 Startup 用依賴注入註冊 appsettings.json,如此一來在應用程式中就能讀取 appsettings.json 中的字串當作設定值,其好處是不需要在 Azure 環境裡手動設定環境變數,但是 TimerTriggerAttributecron-style 字串不能透過此方式來設定。

再者,azure-functions-core-tools #122 表明了 local.setting.json 已經被視作 Function App 的 appsettings.json,所以若非必要,我不推薦自己額外弄一個 appsettings.json。

SubscriptionStatusScheduler

每 10 秒發送一次 HTTP GET 到 DemoApp。

在這個 Scheduler 中,我單純透過 Environment.GetEnvironmentVariable 來讀取 local.settings.json 所設定的環境變數,就不額外新增一個 appsettings.json 了。

注意到 SubscriptionStatusScheduler.cs 使用 TimerTriggerAttribute 的地方:

[TimerTrigger("%Schedule%")] TimerInfo myTimer

"%Schedule%" 在 Function App 啟動時會把 local.setting.json 的 "Schedule": "*/10 * * * * *" 作為排程器的設定值。

當佈署到 Azure 上時,需要手動設定環境變數,從 Home > SubscriptionStatusScheduler,在左側找到 Settings > Configuration,選擇 + New Application Setting,填入以下鍵值對:

Name Value
Schedule */10 * * * * *
DemoUrl https://jacklin-scheduler.herokuapp.com/function/status

雖然手動設定環境變數有點麻煩,但是未來想要更改設定值時,只需要在 Azure 上改環境變數然後儲存、重新佈署即可。

schedfuncapps's People

Contributors

blueskyson avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.