Changeset aa734cb0 in rattail


Ignore:
Timestamp:
11/20/2022 03:30:25 PM (2 months ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
3e17fc4
Parents:
bea5278
Message:

Add basic rattail overnight command, for running luigi tasks

although at this stage, it isn't very aware of luigi, and just knows
to run the "script" associated with given task defined in config

Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • rattail/luigi/handler.py

    rbea5278 raa734cb0  
    148148                return task
    149149
    150     def launch_overnight_task(self, task, date, **kwargs):
     150    def launch_overnight_task(self, task, date,
     151                              email_if_empty=True,
     152                              email_key=None,
     153                              with_at=True,
     154                              dry_run=False,
     155                              **kwargs):
     156        """
     157        Launch the given overnight task, to run for the given date.
     158
     159        :param task: An overnight task info dict, e.g. as obtained
     160           from :meth:`get_overnight_task()`.
     161
     162        :param date: Date for which task should run.
     163
     164        :param email_if_empty: If true (the default), then email will
     165           be sent when the task command completes, even if it
     166           produces no output.  If false, then email is sent only if
     167           the command produces output.
     168
     169        :param email_key: Optional config key for email settings to be
     170           used in determining recipients etc.
     171
     172        :param with_at: If true (currently the default), the task
     173           should be scheduled via the ``at`` command, to begin within
     174           the next minute.  (This lets process control return
     175           immediately to the caller.)  If false, the task will run
     176           in-process, and so will begin immediately, but caller must
     177           wait for it to complete.  You are encouraged to specify the
     178           value you want here, as the default may change in the
     179           future.
     180
     181        :param dry_run: If true, log the final command for the task
     182           but do not actually run it.
     183        """
    151184        appdir = self.config.appdir()
    152185
     
    161194               '--no-versioning',
    162195               'run-n-mail',
    163                '-S', "Overnight for {}: {}".format(date, task['description']),
     196               '-S', "Overnight for {}: {}".format(date, task['key']),
    164197               cmd]
    165 
    166         cmd = ['echo', shlex_join(cmd)]
    167         cmd = shlex_join(cmd)
    168 
    169         cmd = "{} | at 'now + 1 minute'".format(cmd)
     198        if email_key:
     199            cmd.extend(['--key', email_key])
     200        if not email_if_empty:
     201            cmd.append('--skip-if-empty')
     202
     203        if with_at:
     204            cmd = ['echo', shlex_join(cmd)]
     205            cmd = shlex_join(cmd)
     206            cmd = "{} | at 'now + 1 minute'".format(cmd)
     207
     208        # log final command
     209        log.debug("launching command in subprocess: %s", cmd)
     210        if dry_run:
     211            log.debug("dry-run mode, so aborting")
     212            return
    170213
    171214        # run command in subprocess
    172         log.debug("launching command in subprocess: %s", cmd)
    173215        try:
    174             subprocess.check_output(cmd, shell=True, env=env,
     216            subprocess.check_output(cmd, shell=with_at, env=env,
    175217                                    stderr=subprocess.PIPE)
    176218        except subprocess.CalledProcessError as error:
  • setup.py

    rbea5278 raa734cb0  
    237237            'make-uuid = rattail.commands.core:MakeUUID',
    238238            'mysql-chars = rattail.commands.mysql:MysqlChars',
     239            'overnight = rattail.commands.luigi:Overnight',
    239240            'populate-batch = rattail.commands.batch:PopulateBatch',
    240241            'problems = rattail.commands.problems:Problems',
Note: See TracChangeset for help on using the changeset viewer.