Temporal with MicroContainers

Hi,
I implemented some workflows (Multi-tenancy every client has their set of jobs) and I used cron scheduler to run it periodically
that used Quarkus container services.

The problem is I’m some time stop Quarkus container for redeploying. I there’s any way to register the app to temporal server and get the jobs executed again based on their schedules ?

or i have to loop over my tenants in app loading and start them again like that

        WorkflowClient client = configuration.getClient();

        WorkflowOptions workflowOptions = WorkflowOptions.newBuilder()
                .setCronSchedule(EVERY_FIVE_MINUTES)
                .setWorkflowId("getAllListings-"+1000)
                .setTaskQueue(TemporalConfiguration.TASK_QUEUE)
                .setMemo(ImmutableMap.of("action", "getAllListings", "userId", 1000))
                .setWorkflowExecutionTimeout(Duration.ofMinutes(10))
                .setWorkflowRunTimeout(Duration.ofMinutes(10))
                .setWorkflowTaskTimeout(Duration.ofMinutes(10))
                .build();

        // Create a new workflow stub per each workflow start
        GetListingWorkFlow workflow = client.newWorkflowStub(GetListingWorkFlow.class, workflowOptions);
        WorkflowExecution workflowExecution = WorkflowClient
                .start(workflow::startImport, 1000, 154, 100);

        String message = "Started process file workflow with workflowId=\"" + workflowExecution.getWorkflowId()
                + "\" and runId=\"" + workflowExecution.getRunId() + "\"";

Thanks

I think I don’t understand your architecture. In the standard Temporal deployment worker processes are always up and running and periodic jobs are modeled as workflows without the need for any external schedulers.

Could you explain what exactly Quarkus is used for? For running workers periodically (why?) or for starting workflows on schedule?

Thanks for your response. (I have a small experience in temporal). I used Quarkus for enabling or disable the job with REST endpoints for a particular user/tenant (also the services contain business logic implemented in Quarkus). the workflow code is existing in the same quarkus project (I mean GetListingWorkFlow.java and GetListingWorkFlowImpl.java and all activities code too). Currently, the job Is starting and completed successfully.
I used Quarkus corn scheduling setCronSchedule(EVERY_FIVE_MINUTES)
But the issue I mean happens when I want to restart the Quarkus project. I want the jobs to run in the schedule I configured before.

Is there are anyways to do that? OR Should I use Quartz to trigger the job instead of temporal scheduling?

Should store all jobs ids and status for tenant in DB and start them after the app is loading like the code i added before?

If you used Temporal for scheduling then you wouldn’t need to take any action on container restart as Temporal automatically recovers the state of all workflows on any infrastructure failure.

It works as expected. I have to register the app as a client to the temporal server in the Quarkus startup.
Thanks so much.

 WorkflowServiceStubsOptions options = WorkflowServiceStubsOptions.newBuilder()
                .setTarget(.........)
                .build();

        WorkflowServiceStubs service = WorkflowServiceStubs.newInstance(options);

        client = WorkflowClient.newInstance(service);

        WorkerFactory factory = WorkerFactory.newInstance(client);
        Worker worker = factory.newWorker(TASK_QUEUE);
        worker.registerWorkflowImplementationTypes(.......);    // ... others here
        worker.registerWorkflowImplementationTypes(......);

        worker.registerActivitiesImplementations(......);
        worker.registerActivitiesImplementations(......);

        factory.start();