Skip to content

Commit

Permalink
Merge pull request #507 from warunalakshitha/java21
Browse files Browse the repository at this point in the history
Update lang version
  • Loading branch information
warunalakshitha authored Oct 12, 2024
2 parents 5bdb843 + ca976dd commit 4078afe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ballerina/tests/scheduler_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function testLogAndTerminate() returns error? {
_ = check scheduleJobRecurByFrequency(new Job9(), 5, maxCount = 2,
taskPolicy = {errorPolicy: LOG_AND_TERMINATE});
runtime:sleep(10);
test:assertEquals(count9, 1, msg = "Expected count mismatched.");
test:assertEquals(count9, 2, msg = "Expected count mismatched.");
}

int count10 = 0;
Expand All @@ -250,7 +250,7 @@ class Job10 {
function testTerminate() returns error? {
_ = check scheduleJobRecurByFrequency(new Job10(), 5, maxCount = 2, taskPolicy = {errorPolicy: TERMINATE});
runtime:sleep(10);
test:assertEquals(count9, 1, msg = "Expected count mismatched.");
test:assertEquals(count9, 2, msg = "Expected count mismatched.");
}

int count11 = 0;
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.caching=true
group=io.ballerina.stdlib
version=2.5.1-SNAPSHOT

ballerinaLangVersion=2201.10.0-20241002-115300-57eee14c
ballerinaLangVersion=2201.10.0-20241011-161100-51978649
axiomVersion=1.2.22
puppycrawlCheckstyleVersion=10.12.0
ballerinaGradlePluginVersion=2.0.1
Expand Down
25 changes: 15 additions & 10 deletions native/src/main/java/io/ballerina/stdlib/task/utils/TaskJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.ballerina.runtime.api.Runtime;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.types.ObjectType;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.stdlib.task.objects.TaskManager;
Expand All @@ -38,17 +39,21 @@ public TaskJob() {
*/
@Override
public void execute(JobExecutionContext jobExecutionContext) {
Runtime runtime = TaskManager.getInstance().getRuntime();
BObject job = (BObject) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.JOB);
try {
Object result = runtime.call(job, TaskConstants.EXECUTE);
if (result instanceof BError error) {
Thread.startVirtualThread(() -> {
Runtime runtime = TaskManager.getInstance().getRuntime();
BObject job = (BObject) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.JOB);
try {
ObjectType objectType = (ObjectType) job.getOriginalType();
if (objectType.isIsolated() && objectType.isIsolated(TaskConstants.EXECUTE)) {
runtime.startIsolatedWorker(job, TaskConstants.EXECUTE, null, null, null);
} else {
runtime.startNonIsolatedWorker(job, TaskConstants.EXECUTE, null, null, null);
}
} catch (BError error) {
Utils.notifyFailure(jobExecutionContext, error);
} catch (Throwable t) {
Utils.notifyFailure(jobExecutionContext, ErrorCreator.createError(t));
}
} catch (BError error) {
Utils.notifyFailure(jobExecutionContext, error);
} catch (Throwable t) {
Utils.notifyFailure(jobExecutionContext, ErrorCreator.createError(t));
}
});
}
}

0 comments on commit 4078afe

Please sign in to comment.