Skip to content
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
16 changes: 8 additions & 8 deletions client/src/components/StatusBoxAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,20 @@ const StatusBoxAction: FC<IStatusBoxActionProps> = ({ action }) => {
)
}

const RunningProcesses = () => {
const RunningActions = () => {
return ProcessesSection({
title: 'Running processes',
noMessage: 'No running processes',
title: 'Running actions',
noMessage: 'No Running actions',
list: running.filter((a) => a.status === 'running'),
activeTab: activeRunningTab,
onChangeHandler: handleRunningTabChange,
})
}

const ArchiveProcesses = () => {
const FinishedActions = () => {
return ProcessesSection({
title: 'Archive processes',
noMessage: 'No archive processes',
title: 'Finished actions',
noMessage: 'No finished actions',
list: running.filter((a) => ['error', 'finished'].includes(a.status)),
activeTab: activeArchiveTab,
onChangeHandler: handleArchiveTabChange,
Expand Down Expand Up @@ -381,8 +381,8 @@ const StatusBoxAction: FC<IStatusBoxActionProps> = ({ action }) => {
overflow: 'auto',
}}
>
{RunningProcesses()}
{ArchiveProcesses()}
{RunningActions()}
{FinishedActions()}
</Stack>
</Box>
)
Expand Down
7 changes: 5 additions & 2 deletions client/src/context/ActionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ const reducer = (state: State, action: Action): State => {
} else {
updatedProcesses.push(action.process)
}
const idPart = action.process.id.split('-')[1]

const processId = action.process.id.split('-');
processId.shift();
const actionId = processId.join('-')
return {
...state,
processes: updatedProcesses,
started: idPart ? state.started?.add(idPart) : state.started,
started: actionId ? state.started?.add(actionId) : state.started,
}
}
return state
Expand Down
17 changes: 9 additions & 8 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (
)

type launchrServer struct {
actionMngr action.Manager
cfg launchr.Config
ctx context.Context
baseURL string
apiPrefix string
wsMutex sync.Mutex
customize FrontendCustomize
actionMngr action.Manager
cfg launchr.Config
ctx context.Context
baseURL string
apiPrefix string
wsMutex sync.Mutex
customize FrontendCustomize
logsDirPath string
}

// FrontendCustomize stores variables to customize web appearance.
Expand Down Expand Up @@ -353,7 +354,7 @@ func (l *launchrServer) RunAction(w http.ResponseWriter, r *http.Request, id str

// Prepare action for run.
// Can we fetch directly json?
streams, err := createFileStreams(runID)
streams, err := createFileStreams(l.logsDirPath, runID)
if err != nil {
sendError(w, http.StatusInternalServerError, "Error preparing streams")
}
Expand Down
15 changes: 11 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type RunOptions struct {
ClientFS fs.FS
ProxyClient string
FrontendCustomize FrontendCustomize
LogsDirPath string
}

// BaseURL returns base url for run options.
Expand All @@ -70,6 +71,11 @@ func Run(ctx context.Context, app launchr.App, opts *RunOptions) error {
}
swagger.Servers = nil

err = os.MkdirAll(opts.LogsDirPath, 0750)
if err != nil {
return fmt.Errorf("can't create logs dir")
}

ctx, cancel := context.WithCancel(ctx)

// Prepare router and openapi.
Expand All @@ -83,10 +89,11 @@ func Run(ctx context.Context, app launchr.App, opts *RunOptions) error {
MaxAge: 300, // Maximum value not ignored by any of major browsers
}))
store := &launchrServer{
ctx: ctx,
baseURL: opts.BaseURL(),
apiPrefix: opts.APIPrefix,
customize: opts.FrontendCustomize,
ctx: ctx,
baseURL: opts.BaseURL(),
apiPrefix: opts.APIPrefix,
customize: opts.FrontendCustomize,
logsDirPath: opts.LogsDirPath,
}
app.GetService(&store.actionMngr)
app.GetService(&store.cfg)
Expand Down
7 changes: 4 additions & 3 deletions server/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"strings"

"github.com/launchrctl/launchr"
Expand Down Expand Up @@ -92,13 +93,13 @@ func (w *wrappedWriter) Write(p []byte) (int, error) {
return w.w.Write(p)
}

func createFileStreams(runId string) (*webCli, error) {
outfile, err := os.Create(runId + "-out.txt")
func createFileStreams(streamsDir, runId string) (*webCli, error) {
outfile, err := os.Create(filepath.Join(streamsDir, runId+"-out.txt"))
if err != nil {
return nil, fmt.Errorf("error creating output file: %w", err)
}

errfile, err := os.Create(runId + "-err.txt")
errfile, err := os.Create(filepath.Join(streamsDir, runId+"-err.txt"))
if err != nil {
return nil, fmt.Errorf("error creating error file: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions web_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (p *Plugin) runWeb(ctx context.Context, webOpts webFlags) error {
ClientFS: GetClientAssetsFS(),
SwaggerUIFS: swaggerFS,
FrontendCustomize: webOpts.FrontendCustomize,
LogsDirPath: filepath.Join(webOpts.PluginDir, "logs"),
}
go func() {
time.Sleep(time.Second)
Expand Down