It is regulated by Transport Canada.
"Blocked public grade crossings
Under the Grade Crossings Regulations:
- Trains can't block a public grade crossing for more than five minutes when a road user needs to pass, unless the train is moving
- When emergency vehicles need to pass, railway companies must immediately clear any grade crossing
- If the municipality has a safety concern related to a grade crossing that is blocked, both parties must work together to find a solution. If no solution is found after 90 days, the municipality can contact Transport Canada"
https://tc.canada.ca/en/rail-transportation/grade-crossings/public-grade-crossings
If it's a constant thing, talk to your city councillor. Resolution is tried that way first. If you've already complained and gotten no where, try filing a complaint to Transport Canada.
If it's a one-off, sometimes things happen. Equipment breaks down. They are well aware of the rules.