Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dev environment #114

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

watch_file flake.nix
watch_file flake.lock
if ! use flake . --impure
then
echo "devenv could not be built. The devenv environment was not loaded." >&2
fi

2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.21'
- uses: actions/checkout@v3
- name: go mod
run: make mod
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
--health-timeout 5s
--health-retries 5

container: golang:1.20
container: golang:1.21

steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ vendor/
# it's handy to have a docker-compose available during development
docker-compose.yml

.pre-commit-config.yaml

dist/


.devenv/
.direnv/
.pre-commit-config.yaml
10 changes: 0 additions & 10 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ output:
#It's a .golangci.yml config file of this repo: we enable more linters than the default and have more strict settings:

linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
funlen:
Expand Down Expand Up @@ -115,7 +107,6 @@ linters:
- contextcheck
- cyclop
- decorder
- depguard
- dogsled
- dupl
- dupword
Expand Down Expand Up @@ -155,7 +146,6 @@ linters:
- maintidx
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nilnil
Expand Down
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,45 @@ nq.Enqueue(ctx, &jobs.Job{

Additional example integration code can be found at https://github.com/acaloiaro/neoq/tree/main/examples

# Developing

Neoq development is largely based on Nix and `devenv`.

After [installing nix](https://nixos.org/download), this repository contains everything else you will need to develop
and run tests.

## Automatic setup and teardown

See [installing direnv](https://direnv.net/docs/installation.html) if you want the dev environment setup to be automated.

`direnv allow` allows `direnv` to automatically setup all tooling and dependencies in a development shell upon entering
the neoq directory.

## Manual setup and teardown

Neoq uses `devenv` to manage development environments and services.

To enter the development shell, run `nix develop --impure`. If `devenv` is installed, this step is not necessary; simply
enter the neoq directory after having run `direnv allow`.

## Running services for tests

The neoq development shell gives you the `devenv` executable.

To run postgres and redis for tests and development, run

```
devenv up
```

This runs Postgres and Redis in the foreground. In a separate terminal, run `make test` to run the test suite.

## Running tests

Before submitting pull requests, always run tests locally with after having run `devenv up`.

Run `make test` to run the test suite.

# Status

This project is currently in alpha. Future releases may change the API.
This project is currently pre-1.0. Future releases may change the API.
4 changes: 2 additions & 2 deletions backends/memory/memory_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Backend(_ context.Context, opts ...neoq.ConfigOption) (backend neoq.Neoq, e
}

// Enqueue queues jobs to be executed asynchronously
func (m *MemBackend) Enqueue(ctx context.Context, job *jobs.Job) (jobID string, err error) {
func (m *MemBackend) Enqueue(_ context.Context, job *jobs.Job) (jobID string, err error) {
var queueChan chan *jobs.Job
var qc any
var ok bool
Expand Down Expand Up @@ -194,7 +194,7 @@ func (m *MemBackend) SetLogger(logger logging.Logger) {
}

// Shutdown halts the worker
func (m *MemBackend) Shutdown(ctx context.Context) {
func (m *MemBackend) Shutdown(_ context.Context) {
for _, f := range m.cancelFuncs {
f()
}
Expand Down
1 change: 1 addition & 0 deletions backends/postgres/postgres_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ func (p *PgBackend) Enqueue(ctx context.Context, job *jobs.Job) (jobID string, e
}
p.logger.Error("error enqueueing job", slog.String("queue", job.Queue), slog.Any("error", err))
err = fmt.Errorf("error enqueuing job: %w", err)
return
}

err = tx.Commit(ctx)
Expand Down
2 changes: 0 additions & 2 deletions backends/postgres/postgres_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ func TestMultipleCronNodes(t *testing.T) {
_, exists := jobsProcessed.LoadOrStore(job.ID, "foo")
if exists {
t.Fatalf("job (%d) has already been processed by another worker!", job.ID)
atomic.AddUint32(&duplicateJobs, 1)
return nil
}
atomic.AddUint32(&jobsCompleted, 1)
return
Expand Down
2 changes: 1 addition & 1 deletion backends/redis/redis_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (b *RedisBackend) SetLogger(logger logging.Logger) {
}

// Shutdown halts the worker
func (b *RedisBackend) Shutdown(ctx context.Context) {
func (b *RedisBackend) Shutdown(_ context.Context) {
b.client.Close()
b.server.Shutdown()
}
Expand Down
3 changes: 3 additions & 0 deletions bin/gomod2nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!env bash

gomod2nix
Loading
Loading