Changeset 6d8e1e9 in rattail


Ignore:
Timestamp:
07/26/2022 02:24:59 PM (6 months ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
5685603
Parents:
9820a0f
git-author:
Lance Edgar <lance@…> (07/26/2022 02:19:04 PM)
git-committer:
Lance Edgar <lance@…> (07/26/2022 02:24:59 PM)
Message:

Avoid extra sessions in datasync, when fetching config from DB

finally, tracked down why extra sessions were happening..i think.
there may be more instances of this problem elsewhere; will fix as
they're encountered

refs #6, #7

Location:
rattail
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • rattail/app.py

    r9820a0f r6d8e1e9  
    832832        from rattail.db import Session
    833833
    834         # always try to set default continuum user if possible
     834        session = Session(**kwargs)
     835
     836        # try to set continuum user unless kwargs already set it
    835837        if 'continuum_user' not in kwargs:
    836838            if not user:
    837                 user = self.config.get('rattail', 'runas.default')
     839                user = self.config.get('rattail', 'runas.default',
     840                                       session=session)
    838841            if user:
    839                 kwargs['continuum_user'] = user
    840 
    841         return Session(**kwargs)
     842                session.set_continuum_user(user)
     843
     844        return session
    842845
    843846    def cache_model(self, session, model, **kwargs):
  • rattail/config.py

    r9820a0f r6d8e1e9  
    411411        """
    412412        if not hasattr(self, 'app'):
    413             spec = self.get('rattail', 'app.handler',
     413            spec = self.get('rattail', 'app.handler', usedb=False,
    414414                            default='rattail.app:AppHandler')
    415415            factory = load_object(spec)
     
    580580            return url.rstrip('/')
    581581
    582     def datasync_url(self):
     582    def datasync_url(self, **kwargs):
    583583        """
    584584        Returns configured URL for managing datasync daemon.
    585585        """
    586         return self.get('rattail.datasync', 'url')
     586        return self.get('rattail.datasync', 'url', **kwargs)
    587587
    588588    def get_enum(self, **kwargs):
  • rattail/datasync/daemon.py

    r9820a0f r6d8e1e9  
    564564    # amounts of changes land in the queue with same timestamp, and versioning
    565565    # is also enabled.
    566     batch_size = config.getint('rattail.datasync', 'batch_size_limit')
     566    batch_size = config.getint('rattail.datasync', 'batch_size_limit',
     567                               session=session)
    567568    if batch_size and len(changes) > batch_size:
    568569        changes = changes[:batch_size]
     
    594595                    'attempts': attempts,
    595596                    'traceback': ''.join(format_exception(exc_type, exc, traceback)).strip(),
    596                     'datasync_url': config.datasync_url(),
     597                    'datasync_url': config.datasync_url(session=session),
    597598                })
    598599                return False
     
    649650                    'attempts': attempts,
    650651                    'traceback': ''.join(format_exception(exc_type, exc, traceback)).strip(),
    651                     'datasync_url': config.datasync_url(),
     652                    'datasync_url': config.datasync_url(session=session),
    652653                })
    653654                return False
  • rattail/datasync/rattail.py

    r9820a0f r6d8e1e9  
    6161        changes = session.query(model.Change).all()
    6262        session.expunge_all()
     63        # nb. fetch config flag while we have session open
     64        deleted_first = self.config.getbool(
     65            'rattail.datasync', 'rattail_watcher_deleted_first',
     66            session=session,
     67            default=False)
    6368        session.close()
    6469        if not changes:
     
    8691        # so that deletes are processed last, by the consumer(s), to
    8792        # hopefully avoid dependency issues
    88         deleted_first = self.config.getbool(
    89             'rattail.datasync', 'rattail_watcher_deleted_first',
    90             default=False)
    9193        if deleted_first:
    9294            final = deleted + dirty
     
    184186        self.topo_sortkey = make_topo_sortkey(self.model)
    185187
     188    # TODO: deprecate / remove this
    186189    def get_data_model(self):
    187190        """
     
    189192        Defaults to ``rattail.db.model``.
    190193        """
    191         return model
     194        return self.config.get_model()
    192195
    193196    def process_changes(self, host_session, changes):
Note: See TracChangeset for help on using the changeset viewer.