Comments (13)
https://github.com/benmanns/goworker/pull/38/files
from goworker.
I vote this is needed. It would make goworker much more usable to have configuration outside of command line flags.
from goworker.
+1 for this. My app has quite a few (non-goworker-related) configs per-environment that I like to keep in external config files...having to also manage per-environment upstart scripts to manage my Redis host URI's is a bit of a hassle.
from goworker.
@benmanns, any comments on this? Would you accept such a PR?
from goworker.
@twpayne Would configuration stored in environment variables work for your situation?
E.g.
QUEUES=high,medium,low
INTERVAL=0.5
CONCURRENCY=10
./worker
This sort of configuration has been requested in #8, and I'm looking to find the best way to handle it.
from goworker.
In my case my Goworker service shares a number of configuration parameters with other services. I want to have a single configuration file shared by all services to keep it DRY. I suppose I could write a wrapper script that read my configuration file, set environment variables and then exec
ed the Goworker service, but it's rather ugly. It would be much nicer if my Goworker service could read the configuration file itself.
from goworker.
I would second the idea that it's better to allow setting directly, not via environment vars. It would be nice to set the options directly and let the user figure out their own way of storing that data...so the user could (at their choice) read a config file, read env vars, or whatever, then init Goworker with those options.
from goworker.
What would you think about an interface for fetching configuration values? Something like
type Configurator interface {
Get(key string) (*string, error)
}
that could be initialized and passed to goworker. Then we could have predefined goworker.FlagConfigurator
or goworker.EnvConfigurator
, and you can create your own JSONConfigurator
or EtcdConfigurator
, etc.
from goworker.
This is definitely a step in the right direction, but it's not a technique that I've seen elsewhere in Go code. For example, it removes all type checking by forcing the the configuration to be an implicit map[string]string
. Normally things are explicitly configured by passing arguments to some sort of constructor.
Another possibility (not sure if it's a good one):
// Example config from command-line flags
func main() {
goworker.AddFlags()
flag.Parse()
goworker.Run(goworker.ConfigFromFlags())
}
// Example config from environment variables
func main() {
goworker.Run(goworker.ConfigFromEnv())
}
// Example config from explicit config struct
func main() {
config := goworker.Config{
queues: []string{"high", "medium", "low"},
}
goworker.Run(&config)
}
from goworker.
Agreed. What about a "configurator" interface that looks more like:
type Configurator interface {
Get() Config
}
type Config struct {
Queues []string
URI string
Interval float64
// ...
}
I'm trying to avoid requiring everyone who relies on the flag-based configuration to have to add the
goworker.AddFlags()
flag.Parse()
goworker.Run(goworker.ConfigFromFlags())
block when they upgrade.
from goworker.
Is this a case where 100% backwards-compatibility is required? (Aside: I think we're getting hit by Go's primitive package support here). A couple of thoughts:
- Some people might not want goworker to add flags: these might conflict with application-specific flags, or (worse) be silently ignored (but still appear in
-help
) if the user uses a differentConfigurator
. - One way to work around the backwards-incompatible change of
goworker.AddFlags()
and friends is to fail fast and loud if goworker is not configured. Just adding a single mandatory argument to the existinggoworker.Work()
function means that this will be caught immediately at compile time. Users of goworker will go "Ug, what changed?", quickly find what they need to change (because the compiler will point them straight at it), and move on.
from goworker.
+1 on this. I love this library for what it does, but it's doing way too much behind-the-scenes magic for me to feel comfortable. I don't want to have to specify queue name on the command line, for example, because it will never and should never change.
Is there a reason besides a small backwards-incompatible change for why you'd like to optimize for zero-configuration if the user would like to use CLI flags? Does it matter that much for non-trivial applications (which I imagine will want some way of customizing their configuration anyways instead of relying on CLI flags)?
It seems non-idiomatic for a package to add its own mandatory CLI flags (that show up in "--help" output, etc.). That behavior should be completely optional, in my opinion.
from goworker.
The Sidekiq equivalent of this project uses a relatively nice and certainly much more flexible method of configuration: https://github.com/jrallison/go-workers
Could be taken as inspiration for a similar feature for goworker.
from goworker.
Related Issues (20)
- How to panic handling on Job? HOT 2
- 100% cpu usage HOT 17
- Any plans to support Sidekiq backend? HOT 4
- Refactor the Enqueue API
- RabbitMQ Support HOT 1
- Example from Getting Started section doesn't run
- New version HOT 3
- How does goworker work? HOT 4
- Timeout for stuck workers HOT 6
- Any plan to replace garyburd/redigo with gomodule/redigo? HOT 2
- redis please use go-redis
- Supporting Resque Scheduler
- package broken
- missing the prefillParallelism argument in redis.go
- etcd support
- It's graceful, but how to optimize cpu usage? HOT 2
- pools.NewResourcePool request param has changed
- fail to install HOT 4
- There is atomicity problem when worker key is flushed by redis pool
- [Critical] Error on closing worker ip-xxx-xx-xx-xx:xxxxxx-4:xxx: redis: client is closed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goworker.