Rate-limiting Blocks Discourse Workflow

AI-generated summary

The discussion addresses a limitation in Discourse workflows where the 10 executions per minute rate limit blocks critical bulk automation tasks, such as granting badges or subscribing users to a newsletter. gassim highlighted that even using the ‘wait’ feature doesn’t help because the execution is already counted against the limit, causing failures when many users join a group or sign up simultaneously. Gassim proposed implementing a configurable queue system with adjustable delays to handle these spikes.

Frully offered a partial solution for the badge-granting use case, noting that a recent update allows adding a ‘reason’ in workflow actions. Frully suggested using a SQL query with the Data Explorer plugin to identify group members missing a specific badge and then granting it via a scheduled workflow running every few minutes. This approach bypasses the immediate trigger limit by processing users in batches rather than reacting instantly to each individual event.

While gassim appreciated the workaround for badges, they maintained that the core issue remains unresolved for other triggers like user sign-ups or ‘user seen’ events. Gassim argued that simply reducing trigger frequency is insufficient for real-time automation needs, such as immediate newsletter subscriptions upon sign-up. Consequently, the thread emphasizes the need for a more robust queue-based execution model that allows site administrators to define wait times and manage workflow executions more flexibly during high-traffic periods.

Hi
First, thank you for this feature, it’s actually very powerful. Second, I have a question about the rate limit.

Is it possible to change the ‘rate limit’ so it’s not only 10 executions in a minute? The issue with this limitation is that even if I decided to use the “wait” feature, it doesn’t work because the execution is already counted as an execution:

My current use case is to bulk grant badges when members are added to a group, and I use the API endpoint /user_badges.json because this one allows you to mention ‘reason’ (which is not the case in the bulk grant feature nor the workflow action).

However, this might not be the only use case. I’m working on subscribing members to the newsletter as soon as they sign up so if more than ten members join at the same minute, there might be an execution error.

Both use cases are helpful in automating things so that we won’t have to manually subscribe members or grant badges, and there might be quite a number of other similar bulk tasks that we would like to automate. However, the rate limit seems to be a blocker.

The problem with the rate limit is that when many users are imported into a group, the ‘user added to group’ triggers immediately and the execution limit is reached immediately. It would be nice if we can either change the limit or create a queue stack for each specific workflow and a timer for how long to wait before it executes the follow-up execution.

Please feel free to move this post into its own topic post. Thank you!

Good news for part of your problem at least:

The reason can now be attributed in the workflow. The bad news I think the reason field has to be a valid post ID or url. I don’t think there would be much from a group-join api json that would be a valid topic/post there.

Could you instead use sql query to quickly identify who in the group needs the badge (in group and not possessing badge)…then gives it to them.

Data Explorer plugin required:

-- [params]
-- string :group_name = members_uber_group
-- string :badge_name = badge_to_award

SELECT
  u.id AS user_id,
  u.username,
  u.name
FROM users u
JOIN group_users gu ON gu.user_id = u.id
JOIN groups g ON g.id = gu.group_id
WHERE g.name = :group_name
  AND u.id > 0
  AND u.staged IS FALSE
  AND NOT EXISTS (
    SELECT 1
    FROM user_badges ub
    JOIN badges b ON b.id = ub.badge_id
    WHERE ub.user_id = u.id
      AND b.badge_type_id = 3  -- bronze
      AND b.name ILIKE '%' || :badge_name || '%'
  )
ORDER BY u.username

group-members-missing-a-bronze-badge.dcquery.json (1.4 KB)

Workflow:

If it really needs to be timely, then run every few minutes. The sql query is relatively lightweight. According to the AI that authored the workflow, the Grant Badge runs individually on each listed username fed by the Data Explorer Query node.

1 like

Hi @Frully

Thank you for this great idea! It would definitely cover most of the use-cases that would’ve been blocked by the rate-limiting. I’ll definitely test it and see if I can get it to work as expected. I appreciate the SQL query you included and the workflow screenshot. Thank you!!


As for the core request of the topic above related to the rate-limiting, I still believe it would be very helpful if we could have a ‘queue’ and be able to decide the delay/wait-time between executions (instead of being limited by a 10 executions in a minute limit).

Regardless of the ‘use-case’ “grant badges” there will be other triggers such as sign-ups or other actions that might happen more than ten times a minute. For example, conference members or course learners signing up at the same minute… or for example the trigger could be ‘user seen’ and what if it happens that more than 10 members are first seen in the same minute (maybe as a result of an email campaign asking members to come check out something)…etc

The suggested solution “reduce how often its trigger fires” is not sufficient in many use cases.

Thank you!

1 like