How to create a background invisible process?

已回答

Hi!

I need to consume an external API asynchronously (Google Analytics by the way). I was looking documentation about that and found this

https://jetbrains.org/intellij/sdk/docs/basics/architectural_overview/general_threading_rules.html#background-processes-and-processcanceledexception 

And it said:

Background progresses are managed by ProgressManager class, which has plenty of methods to execute the given code with a modal (dialog), non-modal (visible in the status bar), or invisible progress.

So I was do the following:

ProgressManager.getInstance().run(new Task.Backgroundable(null, "Consume API", false) {
    @Override
    public void run(@NotNull ProgressIndicator indicator) {
        // Consuming API stuff
    }
});

 

It's that correct? The documentation talks abouts method for invisible process, but I can't find them.

 

Thanks in advance =)

 

 

 

 
0

Cristóbal, documentation states about an invisible progress, not process.

Your snippet is correct, but you have to be aware that Consume API task will still show up in the current running tasks on the bottom of IDE.

1
Avatar
Permanently deleted user

Thanks Jakub. You're absolutely right! I didn't realize it said "progress" and not "process". Do you have any recommendations for running an asynchronous task in the background?

0

invokeLater should be fine.

0
Avatar
Permanently deleted user

I did that, but I have a synchronous behaviour.

//APIClient

public static void myMethod() {
ApplicationManager.getApplication().invokeLater(() -> {
LOG.info("APIClient.myMethod START");
WebTarget target = client.target("http://host").path("/path");
target.request().method(HttpMethod.GET);
LOG.info("APIClient.myMethod END");
});
}
//MyAbstractGotoSEContributor

@Override
public void fetchWeightedElements(@NotNull String pattern,
@NotNull ProgressIndicator progressIndicator,
@NotNull Processor<? super FoundItemDescriptor<Object>> consumer) {

LOG.info("MyAbstractGotoSEContributor.fetchWeightedElements START");
APIClient.myMethod();

// My stuff
LOG.info("MyAbstractGotoSEContributor.fetchWeightedElements END");
}

So when I run the plugin I have:

MyAbstractGotoSEContributor.fetchWeightedElements START
APIClient.myMethod START
APIClient.myMethod END
MyAbstractGotoSEContributor.fetchWeightedElements END

What I'm doing wrong?

 

Thanks in advance.

 
0

Sorry for the late reply, in that case, you should try with executeOnPooledThread().

1
Avatar
Permanently deleted user

That was exactly the method I used.

Thanks anyway.

0

请先登录再写评论。