Android Question Calling Httpjob inside a Job

sasidhar

Active Member
Licensed User
Longtime User
Hi All,

I tried calling a httpjob inside a job (ie requesting data from server job3 and sending relevant data from mobile local db job4).

Issue is when i get response of 20 strings from job3 httpjob request from server, i could send only few strings say 8 out of 20 from httpjob4), I get no error, job4 sucess message i get in between before completing all strings(ie 20) and stops, this is implemented as service.

Pls find the code below..this works well but not all data from request could not send..pls help to resolve this issue..

Thx
Sasidhar.M


Sub JobDone (Job As HttpJob)
Try
dim ssql as string
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "Job1"
'print the result to the logs
ToastMessageShow("Sucess", True)
Case "Job2"

ToastMessageShow("Sucess", True)
Case "Job3"

ToastMessageShow("Sync Start",True)
Dim parser As JSONParser
Dim response As String
'response = HttpUtils.GetString(ServerUrl)
'response = htjob3.GetString2(ServerUrl)
response=htjob3.GetString
parser.Initialize(response)
Dim rows As List
rows = parser.NextArray
'work with result
'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
If rows.Size > 0 Then
For i = 0 To rows.Size - 1
Log("Rows #" & i)
Dim m As Map
m = rows.Get(i)
ToastMessageShow(m.Get("seqNo") & " , " & m.Get("SeqDate") ,True)
dim tCursor2 as cursor
ssql="SELECT * FROM data_table where param8= " & "'" & aIME1 & "'"
tCursor2 = ssql1.ExecQuery(ssql)
If tCursor2.RowCount>0 Then
tCursor2.Position = i
dim pparam1,pparam2,pparam3,pparam4,pparam5,pparam6,pparam7,pparam8,pparam9,pparam10,pparam11,pparam12 as string
dim ss as string
dim htjob4 as HttpJob
htjob4.Initialize("Job4", Me)
pparam1=(tCursor2.GetString("param1"))
pparam2=(tCursor2.GetString("param2"))
pparam3=(tCursor2.GetString("param3"))
pparam4=(tCursor2.GetString("param4"))
pparam5=(tCursor2.GetString("param5"))
pparam6=(tCursor2.GetString("param6"))
pparam7=(tCursor2.GetString("param7"))
pparam8=(tCursor2.GetString("param8"))
pparam9=(tCursor2.GetString("param9"))
pparam10=(tCursor2.GetString("param10"))
pparam11=(tCursor2.GetString("param11"))
pparam12=(tCursor2.GetString("param12"))
ss= ServerUrl & "param1=" & pparam1 & "&param2=" & pparam2 & "&param3=" & pparam3 & "&param4=" & pparam4 & "&param5=" & pparam5 & "&param6=" & pparam6 & "&param7=" & pparam7 & "&param8=" & pparam8 & "&param9=" & pparam9 & "&param10=" & pparam10 & "&param11=" & pparam11 & "&param12=" & pparam12
htjob4.PostString(ss,"")
end if
tCursor2.close
ToastMessageShow("Data posting From Mobile2Server InProgress.." & i & " of " & rows.Size, True)

Next
Else
ToastMessageShow("No data Found" ,True)
End If
Case "Job4"
'print the result to the logs
ToastMessageShow("Data posting Complete", True)
Case "Job5"
'print the result to the logs
ToastMessageShow("Sucess", True)
Case "Job6"
'print the result to the logs
ToastMessageShow("Sucess", True)
End Select
Else
' Log("Error: " & Job.ErrorMessage)
' Msgbox("Error: " & Job.ErrorMessage,"error")
ToastMessageShow("Error" , True)

End If
Job.Release
Catch
Log(LastException.Message)
End Try
End Sub
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
The problem is here...
B4X:
If rows.Size > 0 Then
For i = 0 To rows.Size - 1
Log("Rows #" & i)
Dim m As Map
m = rows.Get(i)
ToastMessageShow(m.Get("seqNo") & " , " & m.Get("SeqDate") ,True)
dim tCursor2 as cursor
ssql="SELECT * FROM data_table where param8= " & "'" & aIME1 & "'"
tCursor2 = ssql1.ExecQuery(ssql)
If tCursor2.RowCount>0 Then
tCursor2.Position = i
dim pparam1,pparam2,pparam3,pparam4,pparam5,pparam6,pparam7,pparam8,pparam9,pparam10,pparam11,pparam12 as string
dim ss as string
dim htjob4 as HttpJob
htjob4.Initialize("Job4", Me)
You are trying to initialize each job one immediately after the other, which you have discovered doesn't work. You need to check row.size>0 and then just call the first HttpJob. Once you recieve the Job.Success then increment to the next row and initailise the next HttpJob and await the Job.Success again. Repeat until all rows have been completed.

Ps. Please use code tags as it makes reading your sample much easier. Code tags can be added by clicking the "<>" icon.

Kind regards,
RandomCoder
 
Upvote 0

sasidhar

Active Member
Licensed User
Longtime User
Hi,

Thanks for finding the issue and providing solution for same, can you pls share some sample code here to check every job sucess in the loop.

Thx
Sasidhar


The problem is here...
B4X:
If rows.Size > 0 Then
For i = 0 To rows.Size - 1
Log("Rows #" & i)
Dim m As Map
m = rows.Get(i)
ToastMessageShow(m.Get("seqNo") & " , " & m.Get("SeqDate") ,True)
dim tCursor2 as cursor
ssql="SELECT * FROM data_table where param8= " & "'" & aIME1 & "'"
tCursor2 = ssql1.ExecQuery(ssql)
If tCursor2.RowCount>0 Then
tCursor2.Position = i
dim pparam1,pparam2,pparam3,pparam4,pparam5,pparam6,pparam7,pparam8,pparam9,pparam10,pparam11,pparam12 as string
dim ss as string
dim htjob4 as HttpJob
htjob4.Initialize("Job4", Me)
You are trying to initialize each job one immediately after the other, which you have discovered doesn't work. You need to check row.size>0 and then just call the first HttpJob. Once you recieve the Job.Success then increment to the next row and initailise the next HttpJob and await the Job.Success again. Repeat until all rows have been completed.

Ps. Please use code tags as it makes reading your sample much easier. Code tags can be added by clicking the "<>" icon.

Kind regards,
RandomCoder
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Sorry my response was brief earlier, I was on a lunch break at work :D
The idea is not to check the Job.Success from within the loop but to get rid of the For Next Loop completely.
You need to trigger the first HttpJob and await the response. Then from within the response you trigger the next job and so on and so forth until all jobs have been completed. On completion of the last job you can then carry on with the rest of your code by calling a new sub. I'd provide an example, but it turns out that there's already a very good example provided here...
RDC many jobs on one activity - jobdone issue

As you can hopefully see, the HttpJob is called each time from inside the job.success conditional statement where it works through the JobList.

Regards,
RandomCoder
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top