Multiple services using Firebase job dispatcher in android - firebase-job-dispatcher

For an android app, i want start three services using firebase job dispatcher on different days. Can I use same FirebaseDispatcher object for all the three jobs?. Meanwhile, How to maintain same FirebaseDispatcher object even though app is closed?. If i use static object it will be cleared if app crashes. So how to maintain my FirebaseDispatcher object for scheduling multiple services using same dispatcher object? or Can I create different FirebaseDispatcher object for different services? Is it good practice?

You can use the same FirebaseJobDispatcher for all Jobs.
When the application is closed, your Jobs will be executed. How? This is the Android OS concern.
You simply describe when and how your Jobs will be launched. It's all. Read the documentation again and see the comments in the source code of the library.
You can create the new FirebaseJobDispatcher for different Jobs.
Misapplication of static objects -- is bad practice.
So
FirebaseJobDispatcher dispatcher1 =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job job1 = dispatcher1.newJobBuilder()
.setService(YourService1.class)
.setTag(Const.JOB_TAG_1)
// more options to run
.build();
Job job2 = dispatcher1.newJobBuilder()
.setService(YourService2.class)
.setTag(Const.JOB_TAG_2)
// ...
.build();
dispatcher1.mustSchedule(job1);
FirebaseJobDispatcher dispatcher2 =
new FirebaseJobDispatcher(new GooglePlayDriver(context));
dispatcher2.mustSchedule(job2);
dispatcher1.cancel(Const.JOB_TAG_1);
dispatcher2.cancel(Const.JOB_TAG_2);

Related

How to prevent Gtk g_source_timeout_add from triggering in multiple instances

I register a timeout with:
timeout_tag = g_timeout_add(250, update_time, NULL);
and destroys it with
g_source_remove(timeout_tag);
But as I open multiple instances of the same app, the timeout triggers update_time in all instances instead of just one. How would I isolate them?
I'm creating a new application with
app = gtk_application_new("com.lunacd.reminder", G_APPLICATION_FLAGS_NONE);
Should I generate a uuid and append it to com.lunacd.reminder so that the identifier remains distinct?
As #jcoppens pointed out, timeouts are triggered independently. This question is invalid.

How to send data to the main isolate from workmananger's isolate?

My problem is that flutter Hive cannot be opened from multiple isolates. So I want the data fetched in workmananger task to be sent to the main isolate where the hive box is opened and modify it there to avoid corrupting it. I should take into consideration when the app is alive and when it is not => for example when the app is not alive, I edit the hive file directly since it will be only opened in the workmanager isolate whereas if the app is not alive I send the data to the main isolate and edit the hive file. My problem is that I do not know how to track lifecycle within the workmanager task and I do not know how to send the data to the main isolate. Any workarounds or solutions for the problem or how to code the above?
After some research the solution is as follows:
First you register a port on the initialization of the main isolate like this:
void listenToUpdatesFromWorkManager(String name) { var port = ReceivePort(); IsolateNameServer.registerPortWithName(port.sendPort, name); }
You give it a unique name in order to identify it from any other opened isolates like this:
SendPort sendPort = IsolateNameServer.lookupPortByName(name);

Android different languages on concurrent threads

In an Android app I am trying to use different languages at the same time on concurrent threads. One thread is the main UI thread, the other is a background email process sending emails to users in various languages. The problem is when I change the language on one thread it changes the language on the other thread and I get 'language leaks'. Here is the method used to change the language to use the correct resources:
public static Resources getResourcesByLocale(Locale locale, Context context) {
Resources res = context.getResources();
AssetManager am = res.getAssets();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration mainConfig = res.getConfiguration();
Configuration config = new Configuration();
config.setTo(mainConfig);
config.locale = locale;
return new Resources(am, dm, config);
}
This method changes the system wide configuration. So any other process using the configuration will inherit the resources determined by the locale. Is there a way to use multiple configurations one for each locale? I have looked exhaustively for a solution other than calling this method everytime we display text. We want to use this app in Europe and Middle East with about 27 languages.
Any help would be much appreciated.

jBPM 6 - How to hold Task from Rest API

How can I suspend a Task from Rest API.
I'm using the following code
RuntimeEngine engine = sessionBean.getEngine(implementationId);
TaskService taskService = engine.getTaskService();
taskService.start(taskId, actorId);
taskService.complete(taskId, actorId, data);
It works fine, now I want to save task Status between start and complete in different moments, but I don't know How to pass the data Map in order to hold the actual State.
taskService.suspend(taskId, actorId);
You can take a look at the implementation of the Save operation in the jbpm console.
That's done via saving the output values of the task as far as remember. By the way, suspend is not the right method to call to save the state, because it means a completely different thing.
You can start looking at here: https://github.com/droolsjbpm/jbpm-console-ng/blob/master/jbpm-console-ng-human-tasks-forms/jbpm-console-ng-human-tasks-forms-client/src/main/java/org/jbpm/console/ng/ht/forms/client/editors/taskform/FormDisplayPresenter.java
and go down to the actual implementation.
Regards

Necessity of cloning classes for background processes running through rake?

I have a resque worker class which works with ActionMailer and another that works with Mail directly. Here's a short example:
class NotificationWorker
def self.perform(id)
Mailer.delivery_method.settings = {
# custom settings here
}
# Working with Mailer to deliver mails
end
end
Assuming that there may be two workers running on NotificationWorker, I am not sure if these interfer each other. From my understanding, working directly on the Mail class would break functionality because this would result in both mailers using the same settings instead of their assigned ones. A solution would be to create a clone of such a class (which works with ActionMailer, but not with Mail AFAIK).
According to the Resque docs:
Resque workers are rake tasks that run forever. They basically do
this:
start
loop do
if job = reserve
job.process
else
sleep 5 # Polling frequency = 5
end
end
shutdown
I am not familiar with rake besides the basic usage for rails apps. So can anyone enlighten me?
not quite sure what you're trying to achieve here. I have a resque system which queue and delivers automated emails. I have it set up like this:
1) env.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {...}
2) notification_job.rb # its the job not the worker that needs creating.
class NotificationWorker
def self.perform(id)
# Working with Mailer to deliver mails
end
end
If you really need to work with mailer directly and each worker needs different settings then you may need to create a yaml file which relates to a variable that you give the worker on startup.