Skip to content
Open
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
19 changes: 19 additions & 0 deletions bin/opslevel-runner-coding-agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -eu
SCRIPT_DIR="${BASH_SOURCE[0]%/*}"

# source for KUBECONFIG and k8s context to be set
source "$SCRIPT_DIR/setup-kind.sh" opslevel-runner

exec watchexec --watch "$SCRIPT_DIR/../src" --exts go,mod,sum --restart \
-- go run -C "$SCRIPT_DIR/../src" . --log-level TRACE run \
--mode=faktory \
--queues=coding-agent \
--queue=coding-agent \
--job-pod-max-wait=900 \
--runner-pod-namespace=default \
--job-agent-mode=true --metrics-port=10355 \
--job-pod-helper-image=localhost/opslevel-runner:dev \
--job-pod-requests-cpu="${OPSLEVEL_JOB_POD_REQUESTS_CPU:-50}" \
--job-pod-requests-memory="${OPSLEVEL_JOB_POD_REQUESTS_MEMORY:-32}"
1 change: 1 addition & 0 deletions src/Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
faktory: faktory
runner: ../bin/opslevel-runner-runner
coding-agent: ../bin/opslevel-runner-coding-agent
image-builder: watchexec --watch cmd/enqueue.go --watch cmd/root.go --watch main.go --watch go.mod --watch go.sum --watch ../Dockerfile -- HELPER_IMAGE=localhost/opslevel-runner:dev ../bin/build-helper-image.sh opslevel-runner
9 changes: 9 additions & 0 deletions src/cmd/enqueue.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package cmd

import (
"encoding/json"
"fmt"
"os"
"time"

faktory "github.com/contribsys/faktory/client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)
Expand All @@ -32,6 +34,7 @@ var enqueueCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
job, err := readFaktoryJobInput()
cobra.CheckErr(err)

client, err := faktory.Open()
cobra.CheckErr(err)

Expand All @@ -58,6 +61,12 @@ var enqueueCmd = &cobra.Command{
}
}

if log.Debug().Enabled() {
if b, merr := json.Marshal(j); merr == nil {
log.Debug().RawJSON("payload", b).Msg("Submitting Faktory job")
}
}

if job.Batch != "" {
batch, err := client.BatchOpen(job.Batch)
cobra.CheckErr(err)
Expand Down
9 changes: 7 additions & 2 deletions src/cmd/faktory.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func runJob(ctx context.Context, helper worker.Helper, job opslevel.RunnerJob) p
go streamer.Run(ctx)

pkg.MetricJobsProcessing.Inc()
logger.Info().Msgf("Starting job '%s'", job.Id)
logger.Info().Str("job_id", string(job.Id)).Msg("job started")
runner := pkg.NewJobRunner("faktory", cfgFile)
outcome := runner.Run(ctx, job, streamer.Stdout, streamer.Stderr)
streamer.Flush(outcome)
Expand All @@ -186,7 +186,12 @@ func emitJobStartedMetrics() time.Time {

func emitJobCompleteMetrics(jobStart time.Time, job opslevel.RunnerJob, outcome pkg.JobOutcome) {
jobDuration := time.Since(jobStart)
log.Info().Str("outcome", outcome.Message).Msgf("Finished job '%s' took '%s' and had outcome '%s'", job.Id, jobDuration, outcome.Outcome)
log.Info().
Str("job_id", string(job.Id)).
Str("outcome", string(outcome.Outcome)).
Int64("duration_ms", jobDuration.Milliseconds()).
Str("outcome_message", outcome.Message).
Msg("job finished")
pkg.MetricJobsDuration.Observe(jobDuration.Seconds())
pkg.MetricJobsFinished.WithLabelValues(string(outcome.Outcome)).Inc()
pkg.MetricJobsProcessing.Dec()
Expand Down
Loading