Skip to content

Instantly share code, notes, and snippets.

View adampresley's full-sized avatar

Adam Presley adampresley

View GitHub Profile
export function people_beforeInsert(item, context) {
item.fullName = `${item.firstName} ${item.lastName}`;
return item;
}
export function people_beforeUpdate(item, context) {
item.fullName = `${item.firstName} ${item.lastName}`;
return item;
}
cat ./example-raw-json-logs.json | jq -r '.[] | [.app, .time, .msg, .level] | @csv'
cat ./example-raw-json-logs.json | jq -r '.[] | [.app, .time, .msg, .level]'
cat ./example-raw-json-logs.json | jq -r '.[] | .app'
[
{
"app": "main-app",
"time": "2023-01-02T15:23:00Z",
"msg": "Error doing this thing",
"level": "error"
},
{
"app": "main-app",
"time": "2023-01-03T15:23:00Z",
{"app": "main-app","time": "2023-01-02T15:23:00Z","msg":"Error doing this thing","level":"error"}
{"app": "main-app","time": "2023-01-03T15:23:00Z","msg":"Error doing this thing","level":"error"}
{"app": "secondary-app","time": "2023-01-03T15:23:00Z","msg":"Error doing that thing","level":"error"}
{"app": "main-app","time": "2023-01-04T13:23:00Z","msg":"Different error doing this thing","level":"error"}
{"app": "main-app","time": "2023-01-05T17:23:00Z","msg":"Different error doing this thing","level":"error"}
{"app": "secondary-app","time": "2023-01-05T14:23:00Z","msg":"Another error doing this thing","level":"error"}
@adampresley
adampresley / main.go
Created June 14, 2023 21:18
Work Ticker - main.go
package main
import (
"context"
"fmt"
"time"
"github.com/app-nerds/kit/v6/workticker"
"github.com/sirupsen/logrus"
"go.uber.org/ratelimit"
@adampresley
adampresley / WorkTicker.go
Created June 14, 2023 20:58
Work Ticker - WorkTicker.go
package workticker
import (
"context"
"errors"
"sync"
"time"
"github.com/sirupsen/logrus"
"go.uber.org/ratelimit"
@adampresley
adampresley / workticker-part4.go
Created June 14, 2023 20:51
Work Ticker - workticker-part4.go
go func() {
ticker := time.NewTicker(wp.tickFrequency)
for {
select {
case <-ticker.C:
workItem, err := wp.workConfiguration.Retriever(wp.workConfiguration.Handler)
if err != nil && errors.Is(err, ErrNoWorkToRetrieve) {
continue
@adampresley
adampresley / workticker-part3.go
Created June 14, 2023 20:44
Work Ticker - workticker-part3.go
wp.logger.Infof("starting work ticker '%s'...", wp.name)
wg := sync.WaitGroup{}
for i := 0; i < wp.numWorkers; i++ {
wg.Add(1)
go func(workerID int) {
wp.logger.Infof("[%s] starting worker %d", wp.name, workerID)
defer wg.Done()