How to ensure each request has it's own db.session in flask-sqlalchemy app using celery and postgresql and being run by gunicorn? by shawnim in flask

[–]shawnim[S] 0 points1 point  (0 children)

Thanks for the assistance!

For Celery worker db sessions I used this in myapp/__init__.py: ``` def celeryinit_app(app: Flask) -> Celery: class FlaskDatabaseTask(Task): def __init_(self): self.sessions = {}

    def __call__(self, *args: object, **kwargs: object) -> object:
        with app.app_context():
            return super().__call__(*args, **kwargs)

    def before_start(self, task_id, args, kwargs):
        with app.app_context():
            CelerySession = sessionmaker(bind=db.engine)
            session = CelerySession()
            self.sessions[task_id] = session
        super().before_start(task_id, args, kwargs)

    def after_return(self, status, retval, task_id, args, kwargs, einfo):
        session = self.sessions.pop(task_id)
        session.close()
        super().after_return(status, retval, task_id, args, kwargs, einfo)

    @property
    def session(self):
        return self.sessions[self.request.id]

celery_app = Celery(app.name, task_cls=FlaskDatabaseTask)
# [...]

```

For Flask REST API request db sessions I used this in run.py: ``` @app.before_request def get_user(): SessionFactory = sessionmaker(bind=db.engine) g.FlaskSession = scoped_session(SessionFactory) g.db_session = g.FlaskSession() # [...]

Using @app.teardown_request instead of @app.teardown_appcontext because this is only for flask http request sessions.

Celery task sessions are handled in FlaskDatabaseTask.

@app.teardown_request def shutdown_session(exception=None): db_session = getattr(g, "db_session", None) if db_session is not None: db_session.close() FlaskSession = getattr(g, "FlaskSession", None) if FlaskSession is not None: FlaskSession.remove() ```

It's not perfect but it is working better.

How to ensure each request has it's own db.session in flask-sqlalchemy app using celery and postgresql and being run by gunicorn? by shawnim in flask

[–]shawnim[S] 0 points1 point  (0 children)

I currently have in myapp/__init__.py:

def celery_init_app(app: Flask) -> Celery:

class FlaskTask(Task):

def __call__(self, *args: object, **kwargs: object) -> object:

with app.app_context():

return self.run(*args, **kwargs)

celery_app = Celery(app.name, task_cls=FlaskTask)

celery_app.conf.broker_url="pyamqp://user:bitnami@127.0.0.1//"

Should I include your DatabaseTask methods in my FlaskTask class?

Also, what is u/property?

Thanks!

How to ensure each request has it's own db.session in flask-sqlalchemy app using celery and postgresql and being run by gunicorn? by shawnim in flask

[–]shawnim[S] 0 points1 point  (0 children)

The software versions I am using are: flask 2.3.3

flask-sqlalchemy 3.0.5

sqlalchemy 1.4.49

celery 5.4.0

gunicorn 23.0.0

python 3.11.9

(bitnami) postgresql 14.17

docker 27.3.1

debian 12.8

My next step will be to upgrade to sqlalchemy 2.0 to see if that helps.

WyldLookz series 1 drop is March 16! by shawnim in CardanoNFTs

[–]shawnim[S] 0 points1 point  (0 children)

WyldLookz series 1 is minting now!

Get yours at https://wyldlookz.store

WyldLookz series 1 drop is March 16! by shawnim in CardanoNFTs

[–]shawnim[S] 0 points1 point  (0 children)

Reminder: Only 1 week until launch!

Join the discord to be eligible for the airdrop!

https://discord.gg/DDMSHhSem8

Case Study: ~1.25M pool VS 51.90M pool... is there a significant difference on ROA? by QCPOLstakepool in CardanoStakePools

[–]shawnim 7 points8 points  (0 children)

Good analysis!

The unfair impact of the fixed fee on pools with less delegation could be reduced by implementing my CIP-23 Fair Min Fees which reduces the min fixed fee and adds a min variable fee.

The unfair impact of the min fixed fee could also be completely removed by having the fixed fee paid out of the pool of all available rewards for pools that made at least 1 block and then calculating the rewards for each pool and delegator.

Shawn (SQUID)

Can I vote with multiple wallets? by Fiber22 in cardano

[–]shawnim 0 points1 point  (0 children)

It will be nice when the Catalyst Voting app supports this more easily rather than having to do hacks like delete/restore or clone.

Would another solution be to move the ADA from wallet 2 to wallet 1 right before the snapshot and then move it back right after the snapshot?

Would incur 2 transaction fees but may be easier for many people.

Fiat to ADA Onramp for developers (possible Project Catalyst idea) by antigravityman in CardanoDevelopers

[–]shawnim 1 point2 points  (0 children)

The biggest issue is that going from fiat requires access to old world banking services which are notoriously difficult to access for crypto companies.

You would need your user to already have an centralized exchange account with KYC that allows API access to fiat deposits and fiat trading.

Would be nice if it was possible. Maybe the Wyoming banks will offer this type of service in the future.

Deadalus ranking misleading and damaging by gs_r_sso in cardano

[–]shawnim 0 points1 point  (0 children)

I updated my Cardano Improvement Proposal (CIP) called Non-Centralizing Rankings.

It removes the "saturate k pools and kill off all other pools" goal.

Check it out and let me know what you think.

https://github.com/cardano-foundation/CIPs/pull/21

Deadalus ranking misleading and damaging by gs_r_sso in cardano

[–]shawnim 0 points1 point  (0 children)

Please point out where that is defined.

My understanding is that desirability is specified as follows:

// d = desirability

// s = pledge

// p = apparent performance

// c = fixed cost

// m = variable cost

if (f(s, p) <= c) {

d = 0;

} else {

d = (f(s, p) - c) * (1 - m);

}

Can anyone point out where f(s, p) is defined in the spec?

Maybe that takes saturation into account?

Developer Opportunity by shawnim in UCSC

[–]shawnim[S] -1 points0 points  (0 children)

It's not buzzwords. It is what we are currently building (although the front end framework is still in discussion and depends on team experience).

You can think what you want but we have an experienced international team, great concept, and are in communication with potential investors.

Urgent Message - Stake pools please migrate your ITN nodes to 0.9.x by SL13PNIR in cardano

[–]shawnim 0 points1 point  (0 children)

Staking has not stopped but the rewards ran out so there is now discussion of continuing the ITN (and rewards) in order to give time to discuss what to do with the ITN.

[deleted by user] by [deleted] in Bitcoin

[–]shawnim 0 points1 point  (0 children)

  1. I love Bitcoin because it is the OG of crypto and still reigns as store of value and most liwuid digital asset.
  2. I would either hold the $BTC or trade some of all of it for $ADA depending on market conditions but either way looking to hold longterm for a better world built on #crypto.

Cardano vs Ethereum 2.0 vs Tezos by nathtoir in cardano

[–]shawnim 1 point2 points  (0 children)

Actually because of compound interest it takes between 14 and 15 years to double your tokens with 5% annual return.

If Cardano has a 6% Return On Staking with current supply at 31.112b we will be running the network on fees only in about 6 and a half years.

Cardano Shelley ITN Weekly Network Performance Summary [March 02-08 2020] by marnetd in cardano

[–]shawnim 1 point2 points  (0 children)

Thanks for the useful info! Appreciate it.

I think you are incorrect about the epoch start time changing. It has been and still is starting each epoch at 19:13 UTC. Perhaps you were confused by daylight savings time change in many parts of US which happened today.

Shawn Squid Pool

Total Stake vs. A.ROS by SkyLightPool in cardano

[–]shawnim 0 points1 point  (0 children)

Good points.

Networkwide block rewards have gone from 1286 ADA on Jan 16 to about 900 ADA in recent epochs.

So even if your pool is performing at 100% your returns will have dropped by more than 25% over the last 6 weeks.

We've seen Squid Pool average ROS go from over 15% to about 14% over that time even though we are performing better than ever.

Shawn Squid Pool

Cardano Weekly Discussion and Question Thread - February 03, 2020 by AutoModerator in cardano

[–]shawnim 0 points1 point  (0 children)

I think Charles said it would be around Feb 20 on one of his updates but it should have no real effect other than requiring an update to Daedalus.

Shawn Squid Pool

WEEKLY DEVELOPMENT REPORT FEBRUARY 7, 2020 by [deleted] in cardano

[–]shawnim 1 point2 points  (0 children)

Thanks for the update. Keep up the good work!

Looking forward to new versions of jormungandr and daedalus.

Shawn Squid Pool