-
Notifications
You must be signed in to change notification settings - Fork 23
Offline Tasks with WebJobs
-
Open the TodosController in the
APIproject. -
Remove the comments from the AddChangeNotification helper method.
private void AddChangeNotification()
{
var queue = new EventQueue();
queue.AddNotification();
}The current version of the WebJobs SDK does not support the Local Storage Emulator, the tool that simulates Azure storage on local development environments. The WebJobs SDK is using features that are not yet available in the local emulator. As a workaround, a Storage Account needs to be created within Azure, and local machines configured to use the remote location.
This requirement should go away with a future release of the storage emulator. This is a known issue and hopefully will be addressed soon.
- Create a storage Account in the Azure Management Portal for local development use.
- Click Manage Access Keys.
- Note the Storage Account Name and copy the Primary Access Key to the clipboard using the Copy icon. You will use these values to build your connection string.
- Update connection strings from Emulator connection string to live connection string.
- Update the
web.configin theAPIproject
<add name="storage"
connectionString="DefaultEndpointsProtocol=https; AccountName=[accountName]; AccountKey=[accessKey]"/>
```
- Update the
app.configin theProcessorproject.
<add name="AzureJobsRuntime"
connectionString="DefaultEndpointsProtocol=https; AccountName=[accountname]; AccountKey=[accesskey]"/>
<add name="AzureJobsData"
connectionString="DefaultEndpointsProtocol=https; AccountName=[accountname]; AccountKey=[accesskey]"/>
```
We recommend that this Storage account be different than the Production storage account. The connection strings will be overridden in the Portal in a later step much like they were with the database connection string earlier in this workshop.
Important:
Be mindful of your Git commits and code pushes to GitHub, as committing these changes may expose sensitive information through your public GitHub repository.
-
Set
APIas the startup project. -
Start without debugging using
ctrl-F5. -
Set
Processoras the startup project. -
Start debugging with
F5.
You may only attach the debugger in Visual Studio to a single process. In this case we are choosing to attach to the
Processorbecause it is the project we have not run yet. You could also start up the Processor from the command line as it is simply a console application. The choice is yours.
- Start up the gulp server proxied to IIS Express.
gulp run --proxy --proxyPort 31008
-
Validate that new task items are being created and, using the console window, that jobs being picked up from the queue.
-
Shut down the proxy and stop debugging in Visual Studio. You may also want to kill off the instance of IIS Express that was running the API.
-
Set the current working directory to the repository root.
-
Create a scaffolding script for the WebJobs project.
azure site deploymentscript --dotNetConsole .\src\processor\Processor.csproj -s .\src\TodoList.sln -o .\webjobscript
-
Open
webjobscript\deploy.cmd. -
Inspect the Deployment section.
NuGet Restore
The NuGet Restore command is the same as what we have already included in ourdeploy.cmd. Because Package restore is done at the solution level, automatically restoring packages for all projects, we do not need to run this a second time.
MSBuild Differences
In addition to building theProcessorproject instead of our existingAPIproject, the output path is different than our current MSBuild process. This one builds to a sub-folder,\app_data\jobs\continuous\deployedJob. This indicates that this MSBuild Task needs to occur after our existingAPIcompile.
WEB_JOB_DEPLOY_CMD
At first glance, the presence of a new property,WEB_JOB_DEPLOY_CMD, indicates that this may be something required for the primarydeploy.cmd. However, this commands purpose is to copy an HTML file into the website when a WebJob is the only item being deployed. The deployed file is similar to the presence ofhostingstart.htmlwhen the Azure Website was first created, except that this HTML page will notify the visitor that the WebSite is running a WebJob. Because we have other items being deployed, this command is not needed.
KuduSync This KuduSync is identical to the final KuduSync for our current deployment script, synchronizing
%DEPLOYMENT_TEMP%to%DEPLOYMENT_TARGET%. Including it in our primary script would be redundant.
The only step we need to copy is the MSBuild step.
Shiny. There is not a lot to do this time.
- Copy the WebJob's MSBuild step to the clipboard (lines 76-78).
:: 2. Build to the temporary path
call :ExecuteCmd "%MSBUILD_PATH%" "%DEPLOYMENT_SOURCE%\src\processor\Processor.csproj" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath="%DEPLOYMENT_TEMP%\app_data\jobs\continuous\deployedJob" /p:SolutionDir="%DEPLOYMENT_SOURCE%\src\\" %SCM_BUILD_ARGS%
IF !ERRORLEVEL! NEQ 0 goto error
-
Open the primary
deploy.cmdin the repository root. -
Paste this MSBuild step after our
APIMSBuild step, and before our select node version step. -
Change the comments to echo and renumber for diagnostics.
If you like, feel free to use
echo 2a.rather than renumbering the entire script.
call :ExecuteCmd "%MSBUILD_PATH%" "%DEPLOYMENT_SOURCE%\src\api\API.csproj" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release /p:SolutionDir="%DEPLOYMENT_SOURCE%\src\\" %SCM_BUILD_ARGS%
)
IF !ERRORLEVEL! NEQ 0 goto error
echo 2a. Build WebJob to the temporary path
call :ExecuteCmd "%MSBUILD_PATH%" "%DEPLOYMENT_SOURCE%\src\processor\Processor.csproj" /nologo /verbosity:m /t:Build /p:Configuration=Release;OutputPath="%DEPLOYMENT_TEMP%\app_data\jobs\continuous\deployedJob" /p:SolutionDir="%DEPLOYMENT_SOURCE%\src\\" %SCM_BUILD_ARGS%
IF !ERRORLEVEL! NEQ 0 goto error
echo Handling node.js deployment.
- Perform a local deployment.
deploy.cmd
There should now be a
wwwroot\app_datafolder under yourartifactdirectory. That is the new WebJob.
- Commit your changes.
- Create a Storage Account in the Azure Management Portal for production use.
Be sure to create your Storage Account in the same location / Data Center as your Website and SQL Azure Database.
For this Workshop, a locally redundant account is recommended.
- Go to Manage Access Keys. Note the Storage Account Name and copy the Primary Access Key to the clipboard using the Copy icon. Use these values to build your connection string.
DefaultEndpointsProtocol=https; AccountName=[accountName]; AccountKey=[accessKey]
-
Go to your Azure Website within the Management Portal.
-
Navigate to the CONFIGURE tab.
-
Add a connection string entries for
AzureJobsRuntime,AzureJobsData, andstorage, setting each to the connection string created above. Save. -
Push to Azure to deploy the site with the WebJob.
git push azure master
-
Visit the WebJobs tab under your Website on the portal. Verify that it is there and executing.
-
Sit back and think about how cool this really is.