a month ago
What I'm looking for is for the deployment to stop and start every day from 6 pm to 6 am
4 Replies
a month ago
We don't have a built-in scheduler to start and stop a long-running service on a daily schedule. You could achieve this by using the Railway Public API or the CLI from a separate cron-based service to programmatically redeploy/remove your target service on a schedule. If your workload can be restructured as a task that runs and exits, our native Cron Jobs feature lets you trigger a service on a crontab schedule.
Status changed to Awaiting User Response Railway • about 1 month ago
Railway
We don't have a built-in scheduler to start and stop a long-running service on a daily schedule. You could achieve this by using the [Railway Public API](https://docs.railway.com/reference/public-api) or the [CLI](https://docs.railway.com/cli/restart) from a separate cron-based service to programmatically redeploy/remove your target service on a schedule. If your workload can be restructured as a task that runs and exits, our native [Cron Jobs](https://docs.railway.com/cron-jobs) feature lets you trigger a service on a crontab schedule.
a month ago
I tried to do something similar, with github actions, I defined the variables with my railway account, but when trying to turn off the service giving the value of 0 to "numReplicas" or "replicas" it did not work, it gave me an error
{"errors":[{"message":"Error in numReplicas - Invalid input","locations":[{"line":1,"column":12}],"path":["serviceInstanceUpdate"],"extensions":{"code":"INTERNAL_SERVER_ERROR"},"traceId":"2793694241070701294"}],"data":null}
run: |
curl -X POST https://backboard.railway.app/graphql/v2 \
-H "Authorization: Bearer $RAILWAY_TOKEN" \
-H "Content-Type: application/json" \
--data "{\"query\":\"mutation { serviceInstanceUpdate(serviceId: \\\"$SERVICE_ID\\\", environmentId: \\\"$ENV_ID\\\", input: { replicas: 0 }) }\"}"
Status changed to Awaiting Railway Response Railway • about 1 month ago
a month ago
Setting replicas to 0 via serviceInstanceUpdate is not supported. Instead, use the deploymentStop mutation to stop a running deployment and deploymentRedeploy (or environmentTriggersDeploy) to start it again, as documented in our Manage Deployments API guide.
Status changed to Awaiting User Response Railway • about 1 month ago
Railway
Setting replicas to 0 via `serviceInstanceUpdate` is not supported. Instead, use the `deploymentStop` mutation to stop a running deployment and `deploymentRedeploy` (or `environmentTriggersDeploy`) to start it again, as documented in our [Manage Deployments API guide](https://docs.railway.com/integrations/api/manage-deployments).
a month ago
excellent, I was able to do it
- name: Stop active deployment
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
ENV_ID: ${{ secrets.RAILWAY_ENVIRONMENT_ID }}
SERVICE_ID: ${{ secrets.RAILWAY_SERVICE_ID }}
run: |
RESPONSE=$(curl -s -X POST https://backboard.railway.app/graphql/v2 \
-H "Authorization: Bearer $RAILWAY_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"query\":\"query { deployments(input: { projectId: \\\"$PROJECT_ID\\\", environmentId: \\\"$ENV_ID\\\", serviceId: \\\"$SERVICE_ID\\\" }, first: 10) { edges { node { id status } } } }\"}")
echo "Response: $RESPONSE"
DEPLOYMENT_ID=$(echo "$RESPONSE" | jq -r '.data.deployments.edges[] | select(.node.status == "SUCCESS") | .node.id' | head -1)
if [ -z "$DEPLOYMENT_ID" ] || [ "$DEPLOYMENT_ID" = "null" ]; then
echo "No hay deployment activo."
exit 0
fi
echo "Deteniendo deployment: $DEPLOYMENT_ID"
curl -s -X POST https://backboard.railway.app/graphql/v2 \
-H "Authorization: Bearer $RAILWAY_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"query\":\"mutation { deploymentStop(id: \\\"$DEPLOYMENT_ID\\\") }\"}"
echo "Listo."Status changed to Awaiting Railway Response Railway • about 1 month ago
Status changed to Solved thefabi8a • about 1 month ago