Back to articles
The Little Singleton That Could

The Little Singleton That Could

via Dev.to PythonLuis Tor

"I can handle the connections," it said. "I am one. I am shared. I am efficient," it said. And for a while — it could. A Home in settings.py The Singleton lived in settings.py . Not a glamorous address. Nobody visits settings.py to admire the architecture. You go there to set a database password, flip a flag, move on. It's the utility drawer of a Django application — full of things that need to exist somewhere, and settings.py is where they ended up. But the Singleton didn't mind. It had a job, and the job was simple: connect to Consul once, at startup, before the first request ever arrived. Then wait. When someone needed a service address, a config value, a secret — it was already there. Already connected. Already warm. # settings.py CONSUL_CLIENT = consul . connect () One line. That's all it took to exist. And then the app would boot, and the workers would load settings.py , and they'd find it sitting there like a receptionist who'd come in early and made the coffee. I'm already here

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
2 views

Related Articles