0
votes

I am trying to migrated data from one collection to another using azure functions Cosmos trigger. I have set StartFromBeginning=True. I have multiple collections to migrate so I use one function per collection so transfer happens fast.

When I deploy the function it show the status has Running but it actually does not start the transfer unless I to a stop and start. Or if I go to the monitor section and go to live metrics then it start. Is there a way for it to start transferring as soon as it is deployed. Am I messing a setting?

For example I deployed a function yesterday night and today morning when I looked at the count of recoreds in the collection there was none. When I went to Monitor section in Azure functions and then to Live app metrics then only I see it initializing and then starts to execute.

Cosmos Trigger

    public async Task Run([CosmosDBTrigger(
        databaseName: "%SourceDatabaseName%", 
        collectionName: "%ContainerName%",
        ConnectionStringSetting = "connectionString",
        StartFromBeginning =true,
        LeaseCollectionName ="%ContainerLeaseName%",
        CreateLeaseCollectionIfNotExists = true)]IReadOnlyList<Document> source,
        [CosmosDB(databaseName:"%TargetDatabaseName%",
        collectionName:"%TargetContainerName%",
        ConnectionStringSetting = "connectionString")]IAsyncCollector<Document> destination,
        ILogger log)

Deploy Script

    az functionapp create `
      -n $functionAppName `
      --storage-account $storageAccountName `
      --consumption-plan-location $location `
      --app-insights $appInsightsName `
      --runtime dotnet `
      -g $resourceGroup

    az functionapp deployment source config-zip `
      -g $resourceGroup -n $functionAppName --src $publishZip

    az functionapp config appsettings set -n $functionAppName -g $resourceGroup `
    --settings "connectionString=$cosmosConnectionString" "ContainerName=$cosmosContainer" "ContainerLeaseName=$($cosmosContainer)Lease" "SourceDatabaseName=$sourceCosmosDb" "TargetDatabaseName=$destCosmosDb" "TargetContainerName=$cosmosContainer" "JobType=$jobType"
1

1 Answers

0
votes

Does your lease collection have any documents in it already? The StartFromBeginning configuration will only fire if the leases collection is empty.

Also, you mentioned that you have multiple collections to migrate, are they all using the same lease collection? If so, it would be better to give them separate lease collections to work with, otherwise the other triggers will see that there is information already in the lease collection and not fire the StartFromBeginning.

Documentation on StartFromBeginning

When set, it tells the Trigger to start reading changes from the beginning of the history of the collection instead of the current time. This only works the first time the Trigger starts, as in subsequent runs, the checkpoints are already stored. Setting this to true when there are leases already created has no effect.

** I recognize this might be better as a comment, but I don't have enough rep unfortunately.