[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-cbd7fb26-ccf6-489b-a3ea-c6ed6eb4f7d1":3,"$fCN2nghoDF9Efw5vs8wardH3SJaK1NO9fiZhBAxbRTcI":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"cbd7fb26-ccf6-489b-a3ea-c6ed6eb4f7d1","azure-functions","Azure Functions开发的专业模式，包括隔离","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-functions\ndescription: Expert patterns for Azure Functions development including isolated\n  worker model, Durable Functions orchestration, cold start optimization, and\n  production patterns. Covers .NET, Python, and Node.js programming models.\nrisk: none\nsource: vibeship-spawner-skills (Apache 2.0)\ndate_added: 2026-02-27\n---\n\n# Azure Functions\n\nExpert patterns for Azure Functions development including isolated worker model,\nDurable Functions orchestration, cold start optimization, and production patterns.\nCovers .NET, Python, and Node.js programming models.\n\n## Patterns\n\n### Isolated Worker Model (.NET)\n\nModern .NET execution model with process isolation\n\n**When to use**: Building new .NET Azure Functions apps\n\n### Template\n\n\u002F\u002F Program.cs - Isolated Worker Model\nusing Microsoft.Azure.Functions.Worker;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Hosting;\n\nvar host = new HostBuilder()\n    .ConfigureFunctionsWorkerDefaults()\n    .ConfigureServices(services =>\n    {\n        \u002F\u002F Add Application Insights\n        services.AddApplicationInsightsTelemetryWorkerService();\n        services.ConfigureFunctionsApplicationInsights();\n\n        \u002F\u002F Add HttpClientFactory (prevents socket exhaustion)\n        services.AddHttpClient();\n\n        \u002F\u002F Add your services\n        services.AddSingleton\u003CIMyService, MyService>();\n    })\n    .Build();\n\nhost.Run();\n\n\u002F\u002F HttpTriggerFunction.cs\nusing Microsoft.Azure.Functions.Worker;\nusing Microsoft.Azure.Functions.Worker.Http;\nusing Microsoft.Extensions.Logging;\n\npublic class HttpTriggerFunction\n{\n    private readonly ILogger\u003CHttpTriggerFunction> _logger;\n    private readonly IMyService _service;\n\n    public HttpTriggerFunction(\n        ILogger\u003CHttpTriggerFunction> logger,\n        IMyService service)\n    {\n        _logger = logger;\n        _service = service;\n    }\n\n    [Function(\"HttpTrigger\")]\n    public async Task\u003CHttpResponseData> Run(\n        [HttpTrigger(AuthorizationLevel.Function, \"get\", \"post\")] HttpRequestData req)\n    {\n        _logger.LogInformation(\"Processing request\");\n\n        try\n        {\n            var result = await _service.ProcessAsync(req);\n\n            var response = req.CreateResponse(HttpStatusCode.OK);\n            await response.WriteAsJsonAsync(result);\n            return response;\n        }\n        catch (Exception ex)\n        {\n            _logger.LogError(ex, \"Error processing request\");\n            var response = req.CreateResponse(HttpStatusCode.InternalServerError);\n            await response.WriteAsJsonAsync(new { error = \"Internal server error\" });\n            return response;\n        }\n    }\n}\n\n### Notes\n\n- In-process model deprecated November 2026\n- Isolated worker supports .NET 8, 9, 10, and .NET Framework\n- Full dependency injection support\n- Custom middleware support\n\n### Node.js v4 Programming Model\n\nModern code-centric approach for TypeScript\u002FJavaScript\n\n**When to use**: Building Node.js Azure Functions\n\n### Template\n\n\u002F\u002F src\u002Ffunctions\u002FhttpTrigger.ts\nimport { app, HttpRequest, HttpResponseInit, InvocationContext } from \"@azure\u002Ffunctions\";\n\nexport async function httpTrigger(\n  request: HttpRequest,\n  context: InvocationContext\n): Promise\u003CHttpResponseInit> {\n  context.log(`Http function processed request for url \"${request.url}\"`);\n\n  try {\n    const name = request.query.get(\"name\") || (await request.text()) || \"world\";\n\n    return {\n      status: 200,\n      jsonBody: { message: `Hello, ${name}!` }\n    };\n  } catch (error) {\n    context.error(\"Error processing request:\", error);\n    return {\n      status: 500,\n      jsonBody: { error: \"Internal server error\" }\n    };\n  }\n}\n\n\u002F\u002F Register function with app object\napp.http(\"httpTrigger\", {\n  methods: [\"GET\", \"POST\"],\n  authLevel: \"function\",\n  handler: httpTrigger\n});\n\n\u002F\u002F Timer trigger example\napp.timer(\"timerTrigger\", {\n  schedule: \"0 *\u002F5 * * * *\",  \u002F\u002F Every 5 minutes\n  handler: async (myTimer, context) => {\n    context.log(\"Timer function executed at:\", new Date().toISOString());\n  }\n});\n\n\u002F\u002F Blob trigger example\napp.storageBlob(\"blobTrigger\", {\n  path: \"samples-workitems\u002F{name}\",\n  connection: \"AzureWebJobsStorage\",\n  handler: async (blob, context) => {\n    context.log(`Blob trigger processing: ${context.triggerMetadata.name}`);\n    context.log(`Blob size: ${blob.length} bytes`);\n  }\n});\n\n### Notes\n\n- v4 model is code-centric, no function.json files\n- Uses app object similar to Express.js\n- TypeScript first-class support\n- All triggers registered in code\n\n### Python v2 Programming Model\n\nDecorator-based approach for Python functions\n\n**When to use**: Building Python Azure Functions\n\n### Template\n\n# function_app.py\nimport azure.functions as func\nimport logging\nimport json\n\napp = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)\n\n@app.route(route=\"hello\", methods=[\"GET\", \"POST\"])\nasync def http_trigger(req: func.HttpRequest) -> func.HttpResponse:\n    logging.info(\"Python HTTP trigger function processed a request.\")\n\n    try:\n        name = req.params.get(\"name\")\n        if not name:\n            try:\n                req_body = req.get_json()\n                name = req_body.get(\"name\")\n            except ValueError:\n                pass\n\n        if name:\n            return func.HttpResponse(\n                json.dumps({\"message\": f\"Hello, {name}!\"}),\n                mimetype=\"application\u002Fjson\"\n            )\n        else:\n            return func.HttpResponse(\n                json.dumps({\"message\": \"Hello, World!\"}),\n                mimetype=\"application\u002Fjson\"\n            )\n    except Exception as e:\n        logging.error(f\"Error processing request: {str(e)}\")\n        return func.HttpResponse(\n            json.dumps({\"error\": \"Internal server error\"}),\n            status_code=500,\n            mimetype=\"application\u002Fjson\"\n        )\n\n@app.timer_trigger(schedule=\"0 *\u002F5 * * * *\", arg_name=\"myTimer\")\ndef timer_trigger(myTimer: func.TimerRequest) -> None:\n    logging.info(\"Timer trigger executed\")\n\n@app.blob_trigger(arg_name=\"myblob\", path=\"samples-workitems\u002F{name}\",\n                  connection=\"AzureWebJobsStorage\")\ndef blob_trigger(myblob: func.InputStream):\n    logging.info(f\"Blob trigger: {myblob.name}, Size: {myblob.length} bytes\")\n\n@app.queue_trigger(arg_name=\"msg\", queue_name=\"myqueue\",\n                   connection=\"AzureWebJobsStorage\")\ndef queue_trigger(msg: func.QueueMessage) -> None:\n    logging.info(f\"Queue message: {msg.get_body().decode('utf-8')}\")\n\n### Notes\n\n- v2 model uses decorators, no function.json files\n- Python runs out-of-process (always isolated)\n- Linux-based hosting required for Python\n- Async functions supported\n\n### Durable Functions - Function Chaining\n\nSequential execution with state persistence\n\n**When to use**: Need sequential workflow with automatic retry\n\n### Template\n\n\u002F\u002F C# Isolated Worker - Function Chaining\nusing Microsoft.Azure.Functions.Worker;\nusing Microsoft.DurableTask;\nusing Microsoft.DurableTask.Client;\n\npublic class OrderWorkflow\n{\n    [Function(\"OrderOrchestrator\")]\n    public static async Task\u003COrderResult> RunOrchestrator(\n        [OrchestrationTrigger] TaskOrchestrationContext context)\n    {\n        var order = context.GetInput\u003COrder>();\n\n        \u002F\u002F Functions execute sequentially, state persisted between each\n        var validated = await context.CallActivityAsync\u003CValidatedOrder>(\n            \"ValidateOrder\", order);\n\n        var payment = await context.CallActivityAsync\u003CPaymentResult>(\n            \"ProcessPayment\", validated);\n\n        var shipped = await context.CallActivityAsync\u003CShippingResult>(\n            \"ShipOrder\", new ShipRequest { Order = validated, Payment = payment });\n\n        var notification = await context.CallActivityAsync\u003Cbool>(\n            \"SendNotification\", shipped);\n\n        return new OrderResult\n        {\n            OrderId = order.Id,\n            Status = \"Completed\",\n            TrackingNumber = shipped.TrackingNumber\n        };\n    }\n\n    [Function(\"ValidateOrder\")]\n    public static async Task\u003CValidatedOrder> ValidateOrder(\n        [ActivityTrigger] Order order, FunctionContext context)\n    {\n        var logger = context.GetLogger\u003COrderWorkflow>();\n        logger.LogInformation(\"Validating order {OrderId}\", order.Id);\n\n        \u002F\u002F Validation logic...\n        return new ValidatedOrder { \u002F* ... *\u002F };\n    }\n\n    [Function(\"ProcessPayment\")]\n    public static async Task\u003CPaymentResult> ProcessPayment(\n        [ActivityTrigger] ValidatedOrder order, FunctionContext context)\n    {\n        \u002F\u002F Payment processing with built-in retry...\n        return new PaymentResult { \u002F* ... *\u002F };\n    }\n\n    [Function(\"OrderWorkflow_HttpStart\")]\n    public static async Task\u003CHttpResponseData> HttpStart(\n        [HttpTrigger(AuthorizationLevel.Function, \"post\")] HttpRequestData req,\n        [DurableClient] DurableTaskClient client,\n        FunctionContext context)\n    {\n        var order = await req.ReadFromJsonAsync\u003COrder>();\n        string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(\n            \"OrderOrchestrator\", order);\n\n        return client.CreateCheckStatusResponse(req, instanceId);\n    }\n}\n\n### Notes\n\n- State automatically persisted between activities\n- Automatic retry on transient failures\n- Survives process restarts\n- Built-in status endpoint for monitoring\n\n### Durable Functions - Fan-Out\u002FFan-In\n\nParallel execution with result aggregation\n\n**When to use**: Processing multiple items in parallel\n\n### Template\n\n\u002F\u002F C# Isolated Worker - Fan-Out\u002FFan-In\nusing Microsoft.Azure.Functions.Worker;\nusing Microsoft.DurableTask;\n\npublic class ParallelProcessing\n{\n    [Function(\"ProcessImagesOrchestrator\")]\n    public static async Task\u003CProcessingResult> RunOrchestrator(\n        [OrchestrationTrigger] TaskOrchestrationContext context)\n    {\n        var images = context.GetInput\u003CList\u003Cstring>>();\n\n        \u002F\u002F Fan-out: Start all tasks in parallel\n        var tasks = images.Select(image =>\n            context.CallActivityAsync\u003CImageResult>(\"ProcessImage\", image));\n\n        \u002F\u002F Fan-in: Wait for all tasks to complete\n        var results = await Task.WhenAll(tasks);\n\n        \u002F\u002F Aggregate results\n        var successful = results.Count(r => r.Success);\n        var failed = results.Count(r => !r.Success);\n\n        return new ProcessingResult\n        {\n            TotalProcessed = results.Length,\n            Successful = successful,\n            Failed = failed,\n            Results = results.ToList()\n        };\n    }\n\n    [Function(\"ProcessImage\")]\n    public static async Task\u003CImageResult> ProcessImage(\n        [ActivityTrigger] string imageUrl, FunctionContext context)\n    {\n        var logger = context.GetLogger\u003CParallelProcessing>();\n        logger.LogInformation(\"Processing image: {Url}\", imageUrl);\n\n        try\n        {\n            \u002F\u002F Image processing logic...\n            await Task.Delay(1000); \u002F\u002F Simulated work\n\n            return new ImageResult\n            {\n                Url = imageUrl,\n                Success = true,\n                ProcessedUrl = $\"processed-{imageUrl}\"\n            };\n        }\n        catch (Exception ex)\n        {\n            logger.LogError(ex, \"Failed to process {Url}\", imageUrl);\n            return new ImageResult { Url = imageUrl, Success = false };\n        }\n    }\n\n    \u002F\u002F Python equivalent\n    \u002F\u002F @app.orchestration_trigger(context_name=\"context\")\n    \u002F\u002F def process_images_orchestrator(context: df.DurableOrchestrationContext):\n    \u002F\u002F     images = context.get_input()\n    \u002F\u002F\n    \u002F\u002F     # Fan-out: Create parallel tasks\n    \u002F\u002F     tasks = [context.call_activity(\"ProcessImage\", img) for img in images]\n    \u002F\u002F\n    \u002F\u002F     # Fan-in: Wait for all\n    \u002F\u002F     results = yield context.task_all(tasks)\n    \u002F\u002F\n    \u002F\u002F     return {\"processed\": len(results), \"results\": results}\n}\n\n### Notes\n\n- Parallel execution for independent tasks\n- Results aggregated when all complete\n- Memory efficient - only stores task IDs\n- Up to thousands of parallel activities\n\n### Cold Start Optimization\n\nMinimize cold start latency in production\n\n**When to use**: Need fast response times in production\n\n### Template\n\n\u002F\u002F 1. Use Premium Plan with pre-warmed instances\n\u002F\u002F host.json\n{\n  \"version\": \"2.0\",\n  \"extensions\": {\n    \"durableTask\": {\n      \"hubName\": \"MyTaskHub\"\n    }\n  },\n  \"functionTimeout\": \"00:30:00\"\n}\n\n\u002F\u002F 2. Add warmup trigger (Premium Plan)\n[Function(\"Warmup\")]\npublic static void Warmup(\n    [WarmupTrigger] object warmupContext,\n    FunctionContext context)\n{\n    var logger = context.GetLogger(\"Warmup\");\n    logger.LogInformation(\"Warmup trigger executed - initializing dependencies\");\n\n    \u002F\u002F Pre-initialize expensive resources\n    \u002F\u002F Database connections, HttpClients, etc.\n}\n\n\u002F\u002F 3. Use static\u002Fsingleton clients with DI\npublic class Startup\n{\n    public void ConfigureServices(IServiceCollection services)\n    {\n        \u002F\u002F HttpClientFactory prevents socket exhaustion\n        services.AddHttpClient\u003CIMyApiClient, MyApiClient>(client =>\n        {\n            client.BaseAddress = new Uri(\"https:\u002F\u002Fapi.example.com\");\n            client.Timeout = TimeSpan.FromSeconds(30);\n        });\n\n        \u002F\u002F Singleton for expensive initialization\n        services.AddSingleton\u003CIExpensiveService>(sp =>\n        {\n            \u002F\u002F Initialize once, reuse across invocations\n            return new ExpensiveService();\n        });\n    }\n}\n\n\u002F\u002F 4. Reduce package size\n\u002F\u002F .csproj - exclude unnecessary dependencies\n\u003CPropertyGroup>\n  \u003CPublishTrimmed>true\u003C\u002FPublishTrimmed>\n  \u003CTrimMode>partial\u003C\u002FTrimMode>\n\u003C\u002FPropertyGroup>\n\n\u002F\u002F 5. Run from package deployment\n\u002F\u002F Azure CLI\n\u002F\u002F az functionapp deployment source config-zip \\\n\u002F\u002F   --resource-group myResourceGroup \\\n\u002F\u002F   --name myFunctionApp \\\n\u002F\u002F   --src myapp.zip \\\n\u002F\u002F   --build-remote true\n\n### Notes\n\n- Cold starts improved ~53% across all regions\u002Flanguages\n- Premium Plan provides pre-warmed instances\n- Warmup trigger initializes before traffic\n- Package deployment can reduce cold start\n\n### Queue Trigger with Error Handling\n\nReliable message processing with poison queue\n\n**When to use**: Processing messages from Azure Storage Queue\n\n### Template\n\n\u002F\u002F C# Isolated Worker - Queue Trigger\nusing Microsoft.Azure.Functions.Worker;\n\npublic class QueueProcessor\n{\n    private readonly ILogger\u003CQueueProcessor> _logger;\n    private readonly IMyService _service;\n\n    public QueueProcessor(ILogger\u003CQueueProcessor> logger, IMyService service)\n    {\n        _logger = logger;\n        _service = service;\n    }\n\n    [Function(\"ProcessQueueMessage\")]\n    public async Task Run(\n        [QueueTrigger(\"myqueue-items\", Connection = \"AzureWebJobsStorage\")]\n        QueueMessage message)\n    {\n        _logger.LogInformation(\"Processing message: {Id}\", message.MessageId);\n\n        try\n        {\n            var payload = JsonSerializer.Deserialize\u003CMyPayload>(message.Body);\n            await _service.ProcessAsync(payload);\n\n            _logger.LogInformation(\"Message processed successfully: {Id}\", message.MessageId);\n        }\n        catch (Exception ex)\n        {\n            _logger.LogError(ex, \"Error processing message: {Id}\", message.MessageId);\n\n            \u002F\u002F Message will be retried up to maxDequeueCount (default 5)\n            \u002F\u002F Then moved to poison queue: myqueue-items-poison\n            throw;\n        }\n    }\n\n    \u002F\u002F Optional: Monitor poison queue\n    [Function(\"ProcessPoisonQueue\")]\n    public async Task ProcessPoison(\n        [QueueTrigger(\"myqueue-items-poison\", Connection = \"AzureWebJobsStorage\")]\n        QueueMessage message)\n    {\n        _logger.LogWarning(\"Processing poison message: {Id}\", message.MessageId);\n\n        \u002F\u002F Log to monitoring, alert, or store for manual review\n        await _service.HandlePoisonMessageAsync(message);\n    }\n}\n\n\u002F\u002F host.json - Queue configuration\n\u002F\u002F {\n\u002F\u002F   \"version\": \"2.0\",\n\u002F\u002F   \"extensions\": {\n\u002F\u002F     \"queues\": {\n\u002F\u002F       \"maxPollingInterval\": \"00:00:02\",\n\u002F\u002F       \"visibilityTimeout\": \"00:00:30\",\n\u002F\u002F       \"batchSize\": 16,\n\u002F\u002F       \"maxDequeueCount\": 5,\n\u002F\u002F       \"newBatchThreshold\": 8\n\u002F\u002F     }\n\u002F\u002F   }\n\u002F\u002F }\n\n### Notes\n\n- Messages retried up to maxDequeueCount times\n- Failed messages moved to poison queue\n- Configure visibilityTimeout for processing time\n- batchSize controls parallel processing\n\n### HTTP Trigger with Long-Running Pattern\n\nHandle work exceeding 230-second HTTP limit\n\n**When to use**: HTTP request triggers long-running work\n\n### Template\n\n\u002F\u002F Async HTTP pattern - return immediately, poll for status\n[Function(\"StartLongRunning\")]\npublic static async Task\u003CHttpResponseData> StartLongRunning(\n    [HttpTrigger(AuthorizationLevel.Function, \"post\")] HttpRequestData req,\n    [DurableClient] DurableTaskClient client,\n    FunctionContext context)\n{\n    var input = await req.ReadFromJsonAsync\u003CWorkRequest>();\n\n    \u002F\u002F Start orchestration (returns immediately)\n    string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(\n        \"LongRunningOrchestrator\", input);\n\n    \u002F\u002F Return status URLs for polling\n    return client.CreateCheckStatusResponse(req, instanceId);\n}\n\n\u002F\u002F Response includes:\n\u002F\u002F {\n\u002F\u002F   \"id\": \"abc123\",\n\u002F\u002F   \"statusQueryGetUri\": \"https:\u002F\u002F...\u002Finstances\u002Fabc123\",\n\u002F\u002F   \"sendEventPostUri\": \"https:\u002F\u002F...\u002Finstances\u002Fabc123\u002FraiseEvent\u002F{eventName}\",\n\u002F\u002F   \"terminatePostUri\": \"https:\u002F\u002F...\u002Finstances\u002Fabc123\u002Fterminate\"\n\u002F\u002F }\n\n\u002F\u002F Alternative: Queue-based pattern without Durable Functions\n[Function(\"StartWork\")]\n[QueueOutput(\"work-queue\")]\npublic static async Task\u003CWorkItem> StartWork(\n    [HttpTrigger(AuthorizationLevel.Function, \"post\")] HttpRequestData req,\n    FunctionContext context)\n{\n    var input = await req.ReadFromJsonAsync\u003CWorkRequest>();\n    var workId = Guid.NewGuid().ToString();\n\n    \u002F\u002F Queue the work, return immediately\n    var workItem = new WorkItem\n    {\n        Id = workId,\n        Request = input\n    };\n\n    \u002F\u002F Return work ID for status checking\n    var response = req.CreateResponse(HttpStatusCode.Accepted);\n    await response.WriteAsJsonAsync(new\n    {\n        workId = workId,\n        statusUrl = $\"\u002Fapi\u002Fstatus\u002F{workId}\"\n    });\n\n    return workItem;\n}\n\n[Function(\"ProcessWork\")]\npublic static async Task ProcessWork(\n    [QueueTrigger(\"work-queue\")] WorkItem work,\n    FunctionContext context)\n{\n    \u002F\u002F Long-running processing here\n    \u002F\u002F Update status in storage for polling\n}\n\n### Notes\n\n- HTTP timeout is 230 seconds regardless of plan\n- Use Durable Functions for async patterns\n- Return immediately with status endpoint\n- Client polls for completion\n\n## Sharp Edges\n\n### HTTP Timeout is 230 Seconds Regardless of Plan\n\nSeverity: HIGH\n\nSituation: HTTP-triggered functions with long processing time\n\nSymptoms:\n504 Gateway Timeout after ~4 minutes.\nRequest terminates before function completes.\nClient receives timeout even though function continues.\nhost.json timeout setting has no effect for HTTP.\n\nWhy this breaks:\nThe Azure Load Balancer has a hard-coded 230-second idle timeout for HTTP\nrequests. This applies regardless of your function app timeout setting.\n\nEven if you set functionTimeout to 30 minutes in host.json, HTTP triggers\nwill timeout after 230 seconds from the client's perspective.\n\nThe function may continue running after timeout, but the client won't\nreceive the response.\n\nRecommended fix:\n\n## Use async pattern with Durable Functions\n\n```csharp\n[Function(\"StartLongProcess\")]\npublic static async Task\u003CHttpResponseData> Start(\n    [HttpTrigger(AuthorizationLevel.Function, \"post\")] HttpRequestData req,\n    [DurableClient] DurableTaskClient client)\n{\n    var input = await req.ReadFromJsonAsync\u003CWorkRequest>();\n\n    \u002F\u002F Start orchestration, returns immediately\n    string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(\n        \"LongRunningOrchestrator\", input);\n\n    \u002F\u002F Returns status URLs for polling\n    return client.CreateCheckStatusResponse(req, instanceId);\n}\n\n\u002F\u002F Client polls statusQueryGetUri until complete\n```\n\n## Use queue-based async pattern\n\n```csharp\n[Function(\"StartWork\")]\npublic static async Task\u003CHttpResponseData> StartWork(\n    [HttpTrigger(AuthorizationLevel.Function, \"post\")] HttpRequestData req,\n    [QueueOutput(\"work-queue\")] out WorkItem workItem)\n{\n    var workId = Guid.NewGuid().ToString();\n\n    workItem = new WorkItem { Id = workId, \u002F* ... *\u002F };\n\n    var response = req.CreateResponse(HttpStatusCode.Accepted);\n    await response.WriteAsJsonAsync(new {\n        id = workId,\n        statusUrl = $\"\u002Fapi\u002Fstatus\u002F{workId}\"\n    });\n    return response;\n}\n```\n\n## Use webhook callback pattern\n\n```csharp\n\u002F\u002F Client provides callback URL\n\u002F\u002F Function queues work, returns 202 Accepted\n\u002F\u002F When done, POST result to callback URL\n```\n\n### Socket Exhaustion from HttpClient Instantiation\n\nSeverity: HIGH\n\nSituation: Creating HttpClient instances inside function code\n\nSymptoms:\nSocketException: \"Unable to connect to remote server\"\n\"An attempt was made to access a socket in a way forbidden\"\nSporadic connection failures under load.\nWorks locally but fails in production.\n\nWhy this breaks:\nCreating a new HttpClient for each request creates a new socket connection.\nSockets linger in TIME_WAIT state for 240 seconds after closing.\n\nIn a serverless environment with high throughput, you quickly exhaust\navailable sockets. This affects all network clients, not just HttpClient.\n\nAzure Functions shares network resources among multiple customers,\nmaking this even more critical.\n\nRecommended fix:\n\n## Use IHttpClientFactory (Recommended)\n\n```csharp\n\u002F\u002F Program.cs\nvar host = new HostBuilder()\n    .ConfigureFunctionsWorkerDefaults()\n    .ConfigureServices(services =>\n    {\n        services.AddHttpClient\u003CIMyApiClient, MyApiClient>(client =>\n        {\n            client.BaseAddress = new Uri(\"https:\u002F\u002Fapi.example.com\");\n            client.Timeout = TimeSpan.FromSeconds(30);\n        });\n    })\n    .Build();\n\n\u002F\u002F MyApiClient.cs\npublic class MyApiClient : IMyApiClient\n{\n    private readonly HttpClient _client;\n\n    public MyApiClient(HttpClient client)\n    {\n        _client = client;  \u002F\u002F Injected, managed by factory\n    }\n\n    public async Task\u003Cstring> GetDataAsync()\n    {\n        return await _client.GetStringAsync(\"\u002Fdata\");\n    }\n}\n```\n\n## Use static client (Alternative)\n\n```csharp\npublic static class MyFunction\n{\n    \u002F\u002F Static HttpClient, reused across invocations\n    private static readonly HttpClient _httpClient = new HttpClient\n    {\n        Timeout = TimeSpan.FromSeconds(30)\n    };\n\n    [Function(\"MyFunction\")]\n    public static async Task Run(...)\n    {\n        var result = await _httpClient.GetAsync(\"...\");\n    }\n}\n```\n\n## Same pattern for Azure SDK clients\n\n```csharp\n\u002F\u002F Also applies to:\n\u002F\u002F - BlobServiceClient\n\u002F\u002F - CosmosClient\n\u002F\u002F - ServiceBusClient\n\u002F\u002F Use DI or static instances\n```\n\n### Blocking Async Calls Cause Thread Starvation\n\nSeverity: HIGH\n\nSituation: Using .Result, .Wait(), or Thread.Sleep in async code\n\nSymptoms:\nDeadlocks under load.\nRequests hang indefinitely.\n\"A task was canceled\" exceptions.\nWorks with low concurrency, fails with high.\n\nWhy this breaks:\nAzure Functions thread pool is limited. Blocking calls (.Result, .Wait())\nhold a thread hostage while waiting, preventing other work.\n\nThread.Sleep blocks a thread that could be handling other requests.\n\nWith multiple concurrent executions, you quickly run out of threads,\ncausing deadlocks and timeouts.\n\nRecommended fix:\n\n## Always use async\u002Fawait\n\n```csharp\n\u002F\u002F BAD - blocks thread\nvar result = httpClient.GetAsync(url).Result;\nsomeTask.Wait();\nThread.Sleep(5000);\n\n\u002F\u002F GOOD - yields thread\nvar result = await httpClient.GetAsync(url);\nawait someTask;\nawait Task.Delay(5000);\n```\n\n## Fix synchronous method calls\n\n```csharp\n\u002F\u002F BAD - sync over async\npublic void ProcessData()\n{\n    var data = GetDataAsync().Result;  \u002F\u002F Blocks!\n}\n\n\u002F\u002F GOOD - async all the way\npublic async Task ProcessDataAsync()\n{\n    var data = await GetDataAsync();\n}\n```\n\n## Configure async in console\u002Fstartup\n\n```csharp\n\u002F\u002F If you must call async from sync context\npublic static void Main(string[] args)\n{\n    \u002F\u002F Use GetAwaiter().GetResult() at entry point only\n    MainAsync(args).GetAwaiter().GetResult();\n}\n\nprivate static async Task MainAsync(string[] args)\n{\n    \u002F\u002F Async code here\n}\n```\n\n### Consumption Plan 10-Minute Timeout Limit\n\nSeverity: MEDIUM\n\nSituation: Running long processes on Consumption plan\n\nSymptoms:\nFunction terminates after 10 minutes.\n\"Function timed out\" in logs.\nIncomplete processing with no error caught.\nWorks in development (with longer timeout) but fails in production.\n\nWhy this breaks:\nConsumption plan has a hard limit of 10 minutes execution time.\nDefault is 5 minutes if not configured.\n\nThis cannot be increased beyond 10 minutes on Consumption plan.\nLong-running work requires Premium plan or different architecture.\n\nRecommended fix:\n\n## Configure maximum timeout (Consumption)\n\n```json\n\u002F\u002F host.json\n{\n  \"version\": \"2.0\",\n  \"functionTimeout\": \"00:10:00\"  \u002F\u002F Max for Consumption\n}\n```\n\n## Upgrade to Premium plan for longer timeouts\n\n```json\n\u002F\u002F Premium plan - 30 min default, unbounded available\n{\n  \"version\": \"2.0\",\n  \"functionTimeout\": \"00:30:00\"  \u002F\u002F Or remove for unbounded\n}\n```\n\n## Use Durable Functions for long workflows\n\n```csharp\n[Function(\"LongWorkflowOrchestrator\")]\npublic static async Task\u003Cstring> RunOrchestrator(\n    [OrchestrationTrigger] TaskOrchestrationContext context)\n{\n    \u002F\u002F Each activity has its own timeout\n    \u002F\u002F Workflow can run for days\n    await context.CallActivityAsync(\"Step1\", input);\n    await context.CallActivityAsync(\"Step2\", input);\n    await context.CallActivityAsync(\"Step3\", input);\n    return \"Complete\";\n}\n```\n\n## Break work into smaller chunks\n\n```csharp\n\u002F\u002F Queue-based chunking\n[Function(\"ProcessChunk\")]\n[QueueOutput(\"work-queue\")]\npublic static IEnumerable\u003CWorkChunk> ProcessChunk(\n    [QueueTrigger(\"work-queue\")] WorkChunk chunk)\n{\n    var results = Process(chunk);\n\n    \u002F\u002F Queue next chunks if more work\n    if (chunk.HasMore)\n    {\n        yield return chunk.Next();\n    }\n}\n```\n\n### .NET In-Process Model Deprecated November 2026\n\nSeverity: HIGH\n\nSituation: Creating new .NET functions or maintaining existing\n\nSymptoms:\nUsing in-process model in new projects.\nDependency conflicts with host runtime.\nCannot use latest .NET versions.\nFuture migration burden.\n\nWhy this breaks:\nThe in-process model runs your code in the same process as the\nAzure Functions host. This causes:\n- Assembly version conflicts\n- Limited to LTS .NET versions\n- No access to latest .NET features\n- Tighter coupling with host runtime\n\nSupport ends November 10, 2026. After this date, in-process apps\nmay stop working or receive no security updates.\n\nRecommended fix:\n\n## Use isolated worker for new projects\n\n```bash\n# Create new isolated worker project\nfunc init MyFunctionApp --worker-runtime dotnet-isolated\n\n# Or with .NET 8\ndotnet new func --name MyFunctionApp --framework net8.0\n```\n\n## Migrate existing in-process to isolated\n\n```csharp\n\u002F\u002F OLD - In-process (FunctionName attribute)\npublic class InProcessFunction\n{\n    [FunctionName(\"MyFunction\")]\n    public async Task\u003CIActionResult> Run(\n        [HttpTrigger] HttpRequest req,\n        ILogger log)\n    {\n        log.LogInformation(\"Processing\");\n        return new OkResult();\n    }\n}\n\n\u002F\u002F NEW - Isolated worker (Function attribute)\npublic class IsolatedFunction\n{\n    private readonly ILogger\u003CIsolatedFunction> _logger;\n\n    public IsolatedFunction(ILogger\u003CIsolatedFunction> logger)\n    {\n        _logger = logger;\n    }\n\n    [Function(\"MyFunction\")]\n    public async Task\u003CHttpResponseData> Run(\n        [HttpTrigger(AuthorizationLevel.Function, \"get\")]\n        HttpRequestData req)\n    {\n        _logger.LogInformation(\"Processing\");\n        return req.CreateResponse(HttpStatusCode.OK);\n    }\n}\n```\n\n## Key migration changes\n- FunctionName → Function attribute\n- HttpRequest → HttpRequestData\n- IActionResult → HttpResponseData\n- ILogger injection → constructor injection\n- Add Program.cs with HostBuilder\n\n### ILogger Not Outputting to Console or AppInsights\n\nSeverity: MEDIUM\n\nSituation: Using dependency-injected ILogger in isolated worker\n\nSymptoms:\nLogs not appearing in local console.\nLogs not appearing in Application Insights.\nLogs work with context.GetLogger() but not injected ILogger.\nMust pass logger through all method calls.\n\nWhy this breaks:\nIn isolated worker model, the dependency-injected ILogger may not\nbe properly connected to the Azure Functions logging pipeline.\n\nLocal development especially affected - logs may go nowhere.\nApplication Insights requires explicit configuration.\n\nThe ILogger from FunctionContext works differently than\nthe injected ILogger\u003CT>.\n\nRecommended fix:\n\n## Configure Application Insights properly\n\n```csharp\n\u002F\u002F Program.cs\nvar host = new HostBuilder()\n    .ConfigureFunctionsWorkerDefaults()\n    .ConfigureServices(services =>\n    {\n        \u002F\u002F Add App Insights telemetry\n        services.AddApplicationInsightsTelemetryWorkerService();\n        services.ConfigureFunctionsApplicationInsights();\n    })\n    .Build();\n```\n\n## Configure logging levels\n\n```json\n\u002F\u002F host.json\n{\n  \"version\": \"2.0\",\n  \"logging\": {\n    \"applicationInsights\": {\n      \"samplingSettings\": {\n        \"isEnabled\": true,\n        \"excludedTypes\": \"Request\"\n      }\n    },\n    \"logLevel\": {\n      \"default\": \"Information\",\n      \"Host.Results\": \"Error\",\n      \"Function\": \"Information\",\n      \"Host.Aggregator\": \"Trace\"\n    }\n  }\n}\n```\n\n## Use context.GetLogger for reliability\n\n```csharp\n[Function(\"MyFunction\")]\npublic async Task Run(\n    [HttpTrigger] HttpRequestData req,\n    FunctionContext context)\n{\n    \u002F\u002F This logger always works\n    var logger = context.GetLogger\u003CMyFunction>();\n    logger.LogInformation(\"Processing request\");\n}\n```\n\n## Local development - check local.settings.json\n\n```json\n{\n  \"IsEncrypted\": false,\n  \"Values\": {\n    \"FUNCTIONS_WORKER_RUNTIME\": \"dotnet-isolated\",\n    \"AzureWebJobsStorage\": \"UseDevelopmentStorage=true\",\n    \"APPLICATIONINSIGHTS_CONNECTION_STRING\": \"InstrumentationKey=...\"\n  }\n}\n```\n\n### Missing Extension Packages Cause Silent Failures\n\nSeverity: MEDIUM\n\nSituation: Using triggers\u002Fbindings without installing extensions\n\nSymptoms:\nFunction not triggering on events.\n\"No job functions found\" warning.\nBindings not working despite correct configuration.\nWorks after adding extension package.\n\nWhy this breaks:\nAzure Functions v2+ uses extension bundles for triggers and bindings.\nIf extensions aren't properly configured or packages aren't installed,\nthe function host can't recognize the bindings.\n\nIn isolated worker, you need explicit NuGet packages.\nIn in-process, you need Microsoft.Azure.WebJobs.Extensions.*.\n\nRecommended fix:\n\n## Check extension bundle (most common)\n\n```json\n\u002F\u002F host.json - Extension bundles handle most cases\n{\n  \"version\": \"2.0\",\n  \"extensionBundle\": {\n    \"id\": \"Microsoft.Azure.Functions.ExtensionBundle\",\n    \"version\": \"[4.*, 5.0.0)\"\n  }\n}\n```\n\n## Install explicit packages for isolated worker\n\n```xml\n\u003C!-- .csproj - Isolated worker packages -->\n\u003CPackageReference Include=\"Microsoft.Azure.Functions.Worker\" Version=\"1.20.0\" \u002F>\n\u003CPackageReference Include=\"Microsoft.Azure.Functions.Worker.Sdk\" Version=\"1.16.0\" \u002F>\n\n\u003C!-- Storage triggers\u002Fbindings -->\n\u003CPackageReference Include=\"Microsoft.Azure.Functions.Worker.Extensions.Storage\" Version=\"6.2.0\" \u002F>\n\n\u003C!-- Service Bus -->\n\u003CPackageReference Include=\"Microsoft.Azure.Functions.Worker.Extensions.ServiceBus\" Version=\"5.14.0\" \u002F>\n\n\u003C!-- Cosmos DB -->\n\u003CPackageReference Include=\"Microsoft.Azure.Functions.Worker.Extensions.CosmosDB\" Version=\"4.6.0\" \u002F>\n\n\u003C!-- Durable Functions -->\n\u003CPackageReference Include=\"Microsoft.Azure.Functions.Worker.Extensions.DurableTask\" Version=\"1.1.0\" \u002F>\n```\n\n## Verify function registration\n\n```bash\n# Check registered functions\nfunc host start --verbose\n\n# Look for:\n# \"Found the following functions:\"\n# If empty, check extensions and attributes\n```\n\n### Premium Plan Still Has Cold Start on New Instances\n\nSeverity: MEDIUM\n\nSituation: Using Premium plan expecting zero cold start\n\nSymptoms:\nStill experiencing cold starts despite Premium plan.\nFirst request to new instance is slow.\nLatency spikes during scale-out events.\nPre-warmed instances not being used.\n\nWhy this breaks:\nPremium plan provides pre-warmed instances, but:\n- Only one pre-warmed instance by default\n- Rapid scale-out still creates cold instances\n- Pre-warmed instances still run YOUR code initialization\n- Warmup trigger runs, but your code may still be slow\n\nPre-warmed means the runtime is ready, not your application.\n\nRecommended fix:\n\n## Add warmup trigger to initialize your code\n\n```csharp\n[Function(\"Warmup\")]\npublic void Warmup(\n    [WarmupTrigger] object warmupContext,\n    FunctionContext context)\n{\n    var logger = context.GetLogger(\"Warmup\");\n    logger.LogInformation(\"Warmup trigger fired\");\n\n    \u002F\u002F Initialize expensive resources\n    _cosmosClient.GetContainer(\"db\", \"container\");\n    _httpClient.GetAsync(\"https:\u002F\u002Fapi.example.com\u002Fhealth\").Wait();\n}\n```\n\n## Configure pre-warmed instance count\n\n```bash\n# Increase pre-warmed instances (costs more)\naz functionapp config set \\\n  --name \u003Capp-name> \\\n  --resource-group \u003Crg> \\\n  --prewarmed-instance-count 3\n```\n\n## Optimize application initialization\n\n```csharp\n\u002F\u002F Lazy initialize heavy resources\nprivate static readonly Lazy\u003CExpensiveClient> _client =\n    new Lazy\u003CExpensiveClient>(() => new ExpensiveClient());\n\n\u002F\u002F Connection pooling\nservices.AddDbContext\u003CMyDbContext>(options =>\n    options.UseSqlServer(connectionString, sql =>\n        sql.MinPoolSize(5)));\n```\n\n## Use always-ready instances (most expensive)\n\n```bash\n# Instances always running, no cold start\naz functionapp config set \\\n  --name \u003Capp-name> \\\n  --resource-group \u003Crg> \\\n  --minimum-elastic-instance-count 2\n```\n\n## Validation Checks\n\n### Hardcoded Connection String\n\nSeverity: ERROR\n\nConnection strings must never be hardcoded\n\nMessage: Hardcoded connection string. Use Key Vault or App Settings.\n\n### Hardcoded API Key in Code\n\nSeverity: ERROR\n\nAPI keys should use Key Vault or App Settings\n\nMessage: Hardcoded API key. Use Key Vault or environment variables.\n\n### Anonymous Authorization Level in Production\n\nSeverity: WARNING\n\nAnonymous endpoints should be protected by other means\n\nMessage: Anonymous authorization. Ensure protected by API Management or other auth.\n\n### Blocking .Result Call\n\nSeverity: ERROR\n\nUsing .Result blocks threads and causes deadlocks\n\nMessage: Blocking .Result call. Use await instead.\n\n### Blocking .Wait() Call\n\nSeverity: ERROR\n\nUsing .Wait() blocks threads\n\nMessage: Blocking .Wait() call. Use await instead.\n\n### Thread.Sleep Usage\n\nSeverity: ERROR\n\nThread.Sleep blocks threads\n\nMessage: Thread.Sleep blocks threads. Use await Task.Delay() instead.\n\n### New HttpClient Instance\n\nSeverity: WARNING\n\nCreating HttpClient per request causes socket exhaustion\n\nMessage: New HttpClient per request. Use IHttpClientFactory or static client.\n\n### HttpClient in Using Statement\n\nSeverity: WARNING\n\nDisposing HttpClient causes socket exhaustion\n\nMessage: HttpClient in using statement. Use IHttpClientFactory for proper lifecycle.\n\n### In-Process FunctionName Attribute\n\nSeverity: INFO\n\nIn-process model deprecated November 2026\n\nMessage: In-process FunctionName attribute. Consider migrating to isolated worker.\n\n### Missing Function Attribute\n\nSeverity: WARNING\n\nIsolated worker requires [Function] attribute\n\nMessage: HttpTrigger without [Function] attribute (isolated worker requires it).\n\n## Collaboration\n\n### Delegation Triggers\n\n- user needs AWS serverless -> aws-serverless (Lambda, API Gateway, SAM)\n- user needs GCP serverless -> gcp-cloud-run (Cloud Run, Cloud Functions)\n- user needs container-based deployment -> gcp-cloud-run (Azure Container Apps or Cloud Run)\n- user needs database design -> postgres-wizard (Azure SQL, Cosmos DB data modeling)\n- user needs authentication -> auth-specialist (Azure AD, Easy Auth, managed identity)\n- user needs complex orchestration -> workflow-automation (Logic Apps, Power Automate)\n\n## When to Use\n- User mentions or implies: azure function\n- User mentions or implies: azure functions\n- User mentions or implies: durable functions\n- User mentions or implies: azure serverless\n- User mentions or implies: function app\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,150,1025,"2026-05-16 13:06:25",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"54ecf7a4-bc1e-447a-9f23-dfde3a7c5e08","1.0.0","azure-functions.zip",10739,"uploads\u002Fskills\u002Fcbd7fb26-ccf6-489b-a3ea-c6ed6eb4f7d1\u002Fazure-functions.zip","009669bb81301f6b914a32f55ce6558a1ad569c8d9400521fcffcaeb7e6fd01a","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":36321}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]