How can a process in a Docker container know when it is invoked as a cron job?
dctaf
PROOP

7 months ago

I have a container that I'd like to use for my API server and as a periodic cron task.

1. How can that container know whether it is being invoked as a cron job or as the API server?
2. Is there an environment variable set?
3. Is there an environment override I can add to railway.json specifically for cron jobs?
4. Is there a way to override the command that is run for cron jobs, as there is with preDeployCommand?

I do not see anything described on https://docs.railway.com/reference/variables#railway-provided-variables that would be applicable.

Solved$20 Bounty

4 Replies

Railway
BOT

7 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


chandrika
EMPLOYEE

7 months ago

Hi there,

We currently don't support this — could you create a separate service for the cron part of the current service?

The service is expected to execute a task, and exit as soon as that task is finished, not leaving any resources open, such as database connections. More on execution requirements below.


Status changed to Awaiting User Response Railway 7 months ago


dctaf
PROOP

7 months ago

Yes, we can. Is it possible to define the cron-related settings in the railway.json Config-as-Code file, or does it have to be configured through the UI? I don't see this in the docs.


Status changed to Awaiting Railway Response Railway 7 months ago


7 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 7 months ago


dctaf

Yes, we can. Is it possible to define the cron-related settings in the railway.json Config-as-Code file, or does it have to be configured through the UI? I don't see this in the docs.

smolpaw
HOBBY

7 months ago

Yes you can do that with config as code: https://docs.railway.com/reference/config-as-code#cron-schedule
Most if not all settings configurable by UI can be defined as code.


Status changed to Solved parmstar 7 months ago


Loading...