flask-crontab icon indicating copy to clipboard operation
flask-crontab copied to clipboard

Allow additional configurations to manually extend the crontab execution command

Open JoHeinem opened this issue 4 years ago • 4 comments

Right now, the configuration only allows to adjust the following two parameters:

Config item Description Default value
CRONTAB_EXECUTABLE The absolute path of crontab /usr/bin/crontab
CRONTAB_LOCK_JOBS Whether lock jobs when running False

However, it would be great if there are two additional configuration variables that allow to add a prefix and a suffix to the command. For example, this could look like the following (taken from the django-crontab project):

CRONTAB_COMMAND_PREFIX

  • something you want to do or declare, before each job gets executed. A good place for environment variables.
  • default: '' (empty string)
  • example: 'STAGE=production'

CRONTAB_COMMAND_SUFFIX

  • something you want to do after each job was executed.
  • default: '' (empty string)
  • example: '2>&1'

That would allow me to redirect the output stream with the suffix and set important environment variables with the prefix configuration.

JoHeinem avatar Oct 07 '21 09:10 JoHeinem

Unlike django-crontab, we don't have to rely on the config, we can also specify that per task.

frostming avatar Oct 07 '21 09:10 frostming

Thanks for the quick reply! Unfortunately, I don't completely understand that. Could you maybe provide an example how I could possibly add a prefix to my function?

JoHeinem avatar Oct 07 '21 09:10 JoHeinem

I mean it is not supported, but we may have more options on how to do it.

frostming avatar Oct 07 '21 15:10 frostming

I mean it is not supported, but we may have more options on how to do it.

Alright, gotcha! Thanks for the clarification. I might provide a PR for the feature in case I find the time for it.

JoHeinem avatar Oct 07 '21 15:10 JoHeinem