Not able to update value in condition in Gatling script

Hi All,

I have a REST API call which gives 1 Million values in response and on that 1 million values I have to set another values, means 1 value for each value. So total 2 million values. If I triggers this in single call to set values, It affects to my environment it would be down or will fail. So I have to divide this task in chunks like,

  1. Step 1 on 1st call I want to fetch Total values (may increases in future so creating dynamic) from REST with limit of 0.
  2. Step 2 Now divide Total Values by Limit which gives value of ‘offset’ then
  3. Step 3 on next rest call value of offset would be Limit + offsetValue it loops until it equals to (totalvalues/limit)

like,
https://someurl.net;limit=5;offset=0 (1st call will start from 0 offset everytime - Must)
https://someurl.net;limit=5;offset=5 (2nd call, limit + offsetvalue 0 + 5 =5)
https://someurl.net;limit=5;offset=10 (3rd call, limit + offsetvalue 5 + 5 = 10) like so on… till it equals to (totalvalues/limit) which is (10,00,000/5)=200,000

The problem I am facing is, offsetValue is not updating here. It takes 0 as offservalue for all the calls “”"/api/assets;limit=$limit;offset=${offsetValue}""" and also unable to set offsetvalue in this condition .asLongAs(session => offsetValue < 10)

Here is the code,

import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._

class testAPI extends Simulation {
    val geturl = System.getProperty("geturl", "https://someurl.net")
    val username = System.getProperty("username", "user")
    val password = System.getProperty("password", "user")

    // How many records want to fetch in a request
    val limit = Integer.getInteger("limit", 5).toInt

    // Starts 1st request with 0 Page then increases to offsetValue + limit like 1st offsetValue=0 then 0+5=5 offsetValue, then 5+5=10 offsetValue increases till its not equal to (total/limit)
    val offsetValue = 0

    val httpProtocol = http
        .basicAuth(username, password)
        .baseURL(geturl)

    //Step 1
    val scn = scenario("Get Total")
            .exec(http("Total Numbers")
            .get(s"""/api/assets;limit=1;offset=0""")
            .check(jsonPath("$.totalCount").findAll.saveAs("total"))
            )

    //Step 2
    //.asLongAs(session => offsetValue <= ("${total}/$limit")) // NOT WORKING, could you pls help to correct this condition?
    .asLongAs(session => offsetValue < 10) // Temporary took 10 as static
    {
        exec(http("List of Assets")
            .get(session =>s"""/api/assets;limit=$limit;offset=${offsetValue}""")
            .check(jsonPath("$.assets[*].id").findAll.saveAs("IdList"))
            )

        .foreach("${IdList}", "idlist") {
            exec(http("Add")
                .post("""/api/assets/${idlist}/ann""")
                .body(StringBody(session =>s"""{"mAnn": {"originCorrelationId": 1, "timeIn" : 111, "timeOut" : 222, "meta": {"title" : "test-title1"}}}"""))
                )
            }

    //Step 3        
    .exec(session => {
            session.set("offsetValue", offsetValue.get + limit.get)
            println("======================================================")
            println("********offsetValue************: ====>>> " + offsetValue)
            println("======================================================")
            session})
    }

    setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}