DataStage calling user-defined server routine in job batch - datastage

Currently, I want to send a mail with log information inside a job batch whenever it got aborted status. My notification activity works fine but I just want to try to send it via job batch code.
I have created a server routine in DataStage which will send mail based on the job name passed through the job batch.
Below is my code for the server routine test.
$INCLUDE DSINCLUDE JOBCONTROL.H
MailArg<-1> = "From: sender#gmail.com"
MailArg<-1> = "To: receiver#gmail.com"
MailArg<-1> = "Subject: Test"
MailArg<-1> = "Body: Job " : Input : " aborted."
mail = DSSendMail(MailArg)
ErrorCode = 0 ;* set this to non-zero to stop the stage/job
When I check this server routine with DSRoutineChecker, the email sent successfully. Then I do some searching and people say that I can call my own defined routine with DEFFUN in job batch code.
But it didn't work for me.
Below is the code in the job batch.
* Setup job_2, run it, wait for it to finish, and test for success
hJob1 = DSAttachJob("job_2", DSJ.ERRFATAL)
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed: job_2", "JobControl")
Abort
End
ErrCode = DSSetDisableProjectHandler(hJob1, #FALSE)
ErrCode = DSSetDisableJobHandler(hJob1, #FALSE)
Call DSSetJobQueue(ErrCode, hJob1, "MediumPriorityJobs")
ErrCode = DSRunJob(hJob1, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob1)
Status = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
* Fatal Error - No Return
DEFFUN test("JOB_2") CALLING "DSU.test"
Call DSLogFatal("Job Failed: job_2", "JobControl")
End
All lines are auto-generated when added the job job_2 except the DEFFUN line at the end. If I replaced the server routine code with the DEFFUN line and sending mail directly, it'd work too.
But I want to call one line each time per job added if there's a lot of jobs, so I go with the server routine for not having to copy/ paste the MailArg paragraph for each job code.
It seems to me that the calling line is having some trouble. Do you guys have any idea how I can do it?

DEFFUN is a compiler declaration, and should appear before any executable statement. It is simply setting up the calling name and argument list for the actual function. For example
DEFFUN test(Arg1) Calling "DSU.test"
Somewhere you need to call your "test" function. For example
ErrCode = test("JOB_2")

If the mail arguments are never going to change, you could leave them in your routine.
Otherwise you can pass them all as a delimited string, or as separate arguments. If you rewrite test to have more than one argument, then the DEFFUN declaration will need to be refined to include the correct number of arguments, and the actual call will have to be provided with that many values for those arguments.

Related

AnyLogic - inheritance of properties in batch block

I want to store process times in my model for each agent of type Box. For this purpose I have created a Java class ProcessData.
My problem is that I always get NullPointerExceptions. I don't know if it's because of my code or the functionality of the batch block.
When the wait block reaches a certain size, all agents of type Box are routed to the batch block. The batch agent then waits in the seize block for staff member. If the agent is then seized, each agent of type Box contained in the batch agent should then get a start processing time. This is my code at enter of the delay block: box.getProcessData().add(new ProcessData(date(), duration()));. Using a constructor, I add the start time and duration as new variables to a new ProcessData entry.
To determine the end time of each Box agent I have the following code at unbatch block entry: box.getProcessData().getLast().setEnd(date());
Since I have a NullPointerException I can't tell exactly where it came from. My guess is that I have a bug with addressing the code: should I use agent. (from batch) or box. (name of original agent before batch)? Or is it not possible to give the batch agent properties that are inherited by the box agent?
First error is at unbatch, so the second code from above and second error is the following public void onExit( Box batch, Box agent ) { _unbatch_onExit_xjal( this, batch, agent ); }.
Following the screenshot of my error:
The problem you have with this model first,is that you are seizing a resource for the batch without releasing that resource... you need to release before unbatch
your error nevertheless is related to some code that you wrote in the on exit action of the unbatch block that you are unfortunately not telling us
But to discover what is null, check with a traceln() the value of the variables that are present in the on exit section of the unbatch in order to print on the screen what is null

MimeKit .Net Core : The target process exited with code -1073741819 while evaluating the function "MimeKit.MimeMessage.ToString"

I am using Mimekit/Mailkit to forward mail in my .Net core app.
The system exits with the following error :
The target process exited with code -1073741819 while evaluating the function "MimeKit.MimeMessage.ToString"
While executing these lines:
var builder = new BodyBuilder();
builder.TextBody = forwardMail.Body ?? string.Empty;
builder.Attachments.Add(new MessagePart { Message = message });
message.Body = builder.ToMessageBody();
It is happening all the time. Why is this? How can I fix this issue ?
You are making the message recursive.
message.Body = something that embeds message
When you call ToString() on it, the message gets written first to a MemoryStream (and from there, gets converted into a string) and the MemoryStream buffer must continue growing without bounds because there is no end to a recursive message.
You likely meant to embed a different message, but your code has a body part of the message pointing back to the top-level message again resulting in an infinite loop when it gets written out.

Talend ETL - running child job in tLoop

I am trying to run a child job in tLoop. The child job connects to salesforce and downloads "Account" object to local SQL Server table. There are problems with connection to Salesforce, it takes few attempts to connect. Hence, I put the connection stuff in child job and now trying to call the child job in a loop. Below is the image of my parent job.
As you can see in image the tRunJob_1 has error because of Salesforce connection problem in child job. This is correct behaviour.
The setRetryConnect that is connected to OnComponentError has this code: context.retryConnect = true;
The setRetryConnect that is connected to OnComponentOk has this code: context.retryConnect = false;
So, I am tripping this context variable depending on whether child job succeeds or fails.
My tLoop looks as below:
I want the tLoop to run as many times till the condition remains true. That is till the time it continues to error out. However, it just iterates once and then stops. Could anyone please let me know what correction need to be done here to make the tLoop work?
I couldn't re-pro your issue with SalesForce but by looking at your job what I feel is that when you say - "it just iterates once and then stops" is the expected behavior.
As per your job flow after the tRunJob you are using OnComponentOk/OnComponentError trigger which would process and stop the job run as it would have completed the job execution. What it would have ideal was to keep everything in a subjob post tLoop so that it will iterate till the condition is met.
Sample job for explanation -
Here used tSetGlobalVar to define a global variable (in place of your context variable). Then use the globalMap variable as ((Boolean)globalMap.get("tLoop")) in your "Condition" for the tLoop.
And then finally run some code in the tJava component that does something and conditionally sets the global variable to false to mark the ending of loop.
tRunJob provides an Return Code ((Integer)globalMap.get("tRunJob_1_CHILD_RETURN_CODE"))
If you're running your child Job a number of times and want your Job to exit with non-Zero if one of these iterations fails, then after each iteration, you should test this return code and store it in your own globalMap Object if it is non-zero
int returnCode = ((Integer)globalMap.get("tRunJob_1_CHILD_RETURN_CODE"));
if (returnCode > 0) {
globalMap.put("tLoop", false);
}
else {
System.out.println(returnCode);
};
Found the answer myself, posting it here so that it may help others. It appears like OnComponentError breaks the tLoop. Disabled the OnComponentError flow and un-checked the 'Die on Child Error' checkbox in tRunJob.
The tLoop remains as it is. No changes here.
The retryConnect will use the below code. It uses CHILD_RETURN_CODE to check whether the child job threw error. In case of success, its value is 0. I am tripping the variable when the child job succeeds, so the loop will stop. As you can see, the tLoop shows 2 iterations, it is working as expected now. Thanks.

Roblox - Trying to get InvokeClient Remote Function Working

In my server script called MainGameScript I have this code block:
local myRemoteFunction = Instance.new("RemoteFunction")
myRemoteFunction.Parent = game.Workspace
myRemoteFunction.Name = "GetBuildInfo"
game.Players.PlayerAdded:connect(function(player)
print("[MainGameScript] added player")
for i,v in pairs(Regions) do
if (v.Value == 0) then
Regions[i].Value = player.UserId
break
end
end
local success, result = pcall(function() return myRemoteFunction:InvokeClient(player) end)
if success then
print(result)
else
print("Error calling RemoteFunction GetBuildInfo")
end
end)
I have a LocalScript in game.Workspace called LocalBuildScript which contains this:
function game.workspace.GetBuildInfo.OnClientInvoke()
print("[GetBuildInfo] will send back local build info")
return "this will be returned to the server caller script"
end
The GetBuildInfo function is never called. I have added some debug print lines to the calling function and the process seems to die at the point where it uses pcall... This is almost verbatim the Remote Function Client Invoke example from the Roblox Wiki, no idea why it is not working and am hoping somebody here has some experience using InvokeClient scripts.
Thanks,
Andy
The reason it isn't running is because LocalScripts being referenced by RemoteFunctions are expected to be inside of the Player instance somewhere in it. I'm fairly certain this is the case, as I've implemented a similar test system, but I held my LocalScript inside of the Player instance.

Stop httputils service in basic4android

I am using basic4android and I made an application that uses httputils services. Sometimes a remote error occurs (possible server overload or limited internet connection) and the application exits with the error message box. The activity closes but httputils service is still running. While I reopen the activity new error occurs, because of the unfinished job of httputils. Everything is OK only if I choose to stop the activity in the second error.
Is there any way to determine if the httputils service is running by a previous instance of my app? Or better, a way to try to stop this service either its running or not.
HttpUtils errors should not cause your program to exit. You should check IsSuccess to make sure that the call succeeded or not.
You can stop the service from running by calling StopService(HttpUtilsService).
Public Sub StationTransfer_Click
Dim job As HttpJob
job.Initialize("MyJob", Me)
Dim URL As String="https://www.yourserver.com/myjob.asmx/GetData?parameter1=abc"
job.Download(URL)
ProgressDialogShow2("Getting data From Server...", True)
End Sub
Sub JobDone(Job As HttpJob)
Select Job.JobName
Case "MyJob"
HandleMyJob(Job)
End Select
Job.Release
End Sub
Sub HandleMyJob(Job As HttpJob)
If Job.Success = False Then
ToastMessageShow("Error downloading Data", True)
ProgressDialogHide
Return
End If
....
end Sub
if there is an httpjob error you catch it in the handler function by looking at the status. if the status is not success than you catch it and display a message.