I’m working on a workflow that uses custom code to send a get request to check if the contact phone number in on the DNC registry. It will work if I send small amounts of agents through less that 200 but as soon as I send more that it come back with a error 504 Gateway Time-out. Online it says this is probably because I am sending to many through at once. So I have been just sending through small section through manually, but this is is not a good long term solution because we have many contacts to run through. Is there a way I can make my work flow send only a few through at once? Like staggering them so they dont all go through at once?
Hi @KLallemont,
Yes, the best way to currently do this is as follows:
- Before the custom code, add a branch, ideally random distribution
- In the first branch place your custom code
- In the second branch add a five minute delay, then use “Go to action” to jump to the custom code
- In the third branch, add a 10 minute delay etc
If your subscription doesn’t contain random splits, you’d have to define other branch criteria to somewhat split the records into delays, e.g. the record ID starting with 1, 2, 3 etc.
Let me know if you have any follow up questions!
Hey all,
In case anyone has a similar situation, we finally found another workround for this, inspired by Karsten’s ideas above.
Assuming it’s a company workflow as an example, enrol the company with whatever your criteria are
Add a custom code workflow and insert this python:
from datetime import datetime, timedelta
import random
def main(event):
# Generate a random delay between 2 and 10 minutes, down to the second
delay_seconds = random.randint(2 * 60, 10 * 60)
# Calculate the target time
target_time = datetime.utcnow() + timedelta(seconds=delay_seconds)
# Convert to milliseconds since epoch (HubSpot format)
hubspot_timestamp = int(target_time.timestamp() * 1000)
return {
“outputFields”: {
“hubspot_timestamp”: hubspot_timestamp
}
}
(You’ll need to indent it right)
Make sure you set an output for the code of hubspot_timestamp, type: datetime
on your company record, create a datetime property (our is called AI Timestamp)
in the workflow, set ‘AI Timestamp’ to the output of the code ‘hubspot_timestamp’
Then add a delay action to the workflow to wait until the time in the ‘AI Timestamp’ property is reached
then proceed to your other actions. we enrol into another workflow.
here’s the whole thing:
What I usually do to stagger workflow enrollments is throw in a few “delay” steps—just add a quick pause between emails or actions so you’re not hitting everyone at once. For example, you could set delays for a few hours or spread them out over a few days. Another trick I’ve seen work well is enrolling contacts in batches by using separate lists. That way, you have better control over timing.


