Azure WebJob Upload Fails with 'Bad Request' Error for Laravel Queue Worker Script

Veronica Donoso 0 Reputation points
2024-12-10T22:08:44.3466667+00:00

Issue Description

I am attempting to set up a WebJob in Azure Web App Service to run a Laravel queue worker (php artisan queue:work). However, when adding the WebJob, I consistently encounter the error: "Failed to add 'queue-worker' Bad request".

Steps Taken to Resolve the Issue

1. WebJob Script

I created a shell script named queue-worker.sh with the following content:

#!/bin/bash

Navigate to the app directory

cd /home/site/wwwroot

Run the Laravel queue worker

php artisan queue:work --sleep=3 --tries=3 --timeout=90

The script was saved in the scripts folder at the root of my Laravel app, alongside artisan, app, public, resources, etc.

2. File Permissions

The script has the correct permissions: -rwxr-xr-x.

3. File Encoding

Initially, the script had Windows-style line endings (CRLF). I converted it to Unix-style line endings (LF) using dos2unix and verified the output using cat -e.

4. ZIP File

I zipped the queue-worker.sh file into queue-worker.zip with the script placed at the root of the ZIP file.

5. App Service Configuration

My app is deployed using Azure Web App Service on a PremiumV2 (P1v2) plan, which supports WebJobs.

I confirmed the following application settings are correctly configured in Azure:

WEBSITE_CONTENTAZUREFILECONNECTIONSTRING: Set to the storage account connection string.

WEBSITE_CONTENTSHARE: Set to the file share name in the storage account.

6. Testing Script Locally

I tested the script locally successfully.

7. WebJob Configuration in Azure

Uploaded the queue-worker.zip file to Azure WebJobs:

Set the WebJob as Continuous.

Each attempt resulted in the error: "Failed to add 'queue-worker' Bad request".

Request for Assistance

I need help understanding why the WebJob upload fails with a "Bad request" error, despite verifying file structure, permissions, encoding, and App Service configuration. Is there any additional configuration or debugging step I should take to resolve this?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,388 questions
{count} votes

2 answers

Sort by: Most helpful
  1. ajkuma 28,041 Reputation points Microsoft Employee
    2024-12-26T04:12:24.61+00:00

    Following-up from the comments, to benefit the community summarizing the answer.

    Scenario:
    Attempting to configure a WebJob in Azure Web App Service to run a Laravel queue worker using the command php artisan queue:work. However, each time to add the WebJob, an error message: "Failed to add 'queue-worker' Bad request" is received.

    Issue:
    Azure WebJob Upload Fails with 'Bad Request' Error When Attempting to Run Laravel Queue Worker Script.

    Copying the solution shared by Veronica Donoso. Our Azure support team helped identify the problem - The issue was due to missing 3 env variables:

    Solution:
    Added the following environments variables.
    Ref: Environment variables and app settings in Azure App Service

    • WEBSITE_SKIP_RUNNING_KUDUAGENT = false
    • WEBSITE_VNET_ROUTE_ALL = 1
    • WEBSITE_CONTENTOVERVNET = 1

    > please click Accept Answer - it will benefit the community/users to find the answer quickly.

    1 person found this answer helpful.
    0 comments No comments

  2. ajkuma 28,041 Reputation points Microsoft Employee
    2024-12-23T11:31:09.9+00:00

    Veronica Donoso, Apologies for the delayed response. Based on the steps you have taken, it seems like you have covered all the necessary configurations required to run a WebJob in Azure Web App Service. To isolate the issue further, you may try the following steps:

    If you haven't done, please ensure that the WEBSITES_ENABLE_APP_SERVICE_STORAGE setting is set to true

    Just to highlight - WebJobs for Linux code is in preview.

    As a test - In addition to shell scripts, WebJobs written in the language of the selected runtime are also supported. In your example - Python (.py) scripts.

    When reproducing the issue, capture F12 network tracke form the browser, as outlined on this doc: Capture a browser trace for troubleshooting

    Try enabling the basic authorization for the App Service. (similar discussion thread)User's image


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.