How to get all statuses for jobs of a specific user?

hello community, i need a small conceptual answer to a question from a more experienced audience

I’m new and found out about your project recently and would like to implement temporal in my golang project

my project is simple,

  1. the user has created a campaign, now or planned (maybe a month or a year in advance),
    -or with the ability to periodically repeat the task,
  • with the ability to cancel the task or pause,
    after that - I add this campaign to the backend in postgres with the status “NEW”,
  1. further I would like to transfer the task to the worker for execution

  2. after the worker completes the task, I need to notify the user about the status of the campaign (I want to do this using web sockets)

And my question is:
Should I, after completing the task as a worker, contact the database every time and change the campaign status to “SUCCESSFULLY”

  1. I have already heard from many that when a huge queue accumulates, it is not the best idea to update the connection to the database every time …

  2. can I get the status of tasks with a temporal for a specific user, for example, when he visits the frontend, “All” of his campaigns with all statuses are loaded,

So what’s the best way to get all these statuses?

I hope that I have described the maximum of what I have is a question, who understood please I would like to hear your experienced opinion

the user has created a campaign, now or planned (maybe a month or a year in advance), or with the ability to periodically repeat the task

With Temporal your user could start workflow execution as cron, another option could be to use updatable timer, a blocking sleep which user could update via signal.

  • with the ability to cancel the task or pause,
    after that - I add this campaign to the backend in postgres with the status “NEW”,

Take a look at cancellation docs and sample.
Typically with Temporal you want to utilize the workflow state as the “source of truth” and might not need an external persistence store for this requirement. You could have a “status” workflow variable you can query from your client code, or could use enhanced visibility search attributes to set this “status” which you can query and filter via client apis.

  1. further I would like to transfer the task to the worker for execution

Can you elaborate more on this?

  1. after the worker completes the task, I need to notify the user about the status of the campaign (I want to do this using web sockets)

You could do this by pushing data from an activity.

Should I, after completing the task as a worker, contact the database every time and change the campaign status to “SUCCESSFULLY”

I believe not, as mentioned earlier you could rely on workflow state (and/or visibility) instead imo.

  1. can I get the status of tasks with a temporal for a specific user, for example, when he visits the frontend, “All” of his campaigns with all statuses are loaded,

One way could be via search attributes and visibility queries. You could upsert the value of a “User” custom search attribute and then use visibility query to look up all workflow executions with a particular value set for this search attribute. Another way could be have “entity workflows” where you can set a user id as the business level workflow id (so each entity workflow would represent campains for one specific user)

So what’s the best way to get all these statuses

If you store these statuses as workflow variables you can use workflow queries, or if you go with advanced visibility features to use list apis with visibility queries.

Hope this helps.

thanks for the answer) you are the only one who helps)

So what’s the best way to get all these statuses

How can I transfer additional information to the workflow, for example, a campaign ID?

  1. I already understood that I can identify all the campaigns of the user by passing the user ID to the workflow (StartWorkflowOptions),

  2. but it is not yet clear how to identify the campaigns separately,

I probably need to transfer the campaign ID somewhere and then make a query to the state by pass this id.s… is there a possibility to do this? and this also needs to be done in StartWorkflowOptions?

more control in the second case? can i rely on the updatable timer as well as cron? do they have the same reliability?

thanks for the answer) you are the only one who helps)

Thanks for kind words, just adding that everyone at Temporal is more than happy to help community with any questions and its very often people from teams like Server, Eng, etc that help with posted answers and are the unsung heroes :slight_smile:

How can I transfer additional information to the workflow, for example, a campaign ID?

I think this depends on how you want to structure your workflows, have a workflow-per-user and could start campaings by signalling this workflow which in turn could invoke a child workflow for this campaign. Another option to have a workflow-per-campaign where you can pass the user id as workflow input and store it in workflow state and/or search attributes if you wanted.

more control in the second case?

Yes i think you would have more control as you could update your timers during workflow execution. All timers are created and persisted by the server so I think you would have the same reliability.

1 Like