Skip to content

Commit

Permalink
Remove the updates worker (#4192)
Browse files Browse the repository at this point in the history
It was deprecated in 2019, has not been maintained, and is probably
broken.
  • Loading branch information
nono committed Oct 25, 2023
2 parents 5a4a5da + 5d82d85 commit 3004306
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 610 deletions.
76 changes: 0 additions & 76 deletions client/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,6 @@ type OAuthClientOptions struct {
OnboardingState string
}

// UpdatesOptions is a struct holding all the options to launch an update.
type UpdatesOptions struct {
Domain string
DomainsWithContext string
Slugs []string
ForceRegistry bool
OnlyRegistry bool
Logs chan *JobLog
}

type ExportOptions struct {
Domain string
LocalPath string
Expand Down Expand Up @@ -407,72 +397,6 @@ func (ac *AdminClient) RegisterOAuthClient(opts *OAuthClientOptions) (map[string
return client, nil
}

// Updates launch the updating process of the applications. When no Domain is
// specified, the updates are launched for all the existing instances.
func (ac *AdminClient) Updates(opts *UpdatesOptions) error {
q := url.Values{
"Domain": {opts.Domain},
"DomainsWithContext": {opts.DomainsWithContext},
"Slugs": {strings.Join(opts.Slugs, ",")},
"ForceRegistry": {strconv.FormatBool(opts.ForceRegistry)},
"OnlyRegistry": {strconv.FormatBool(opts.OnlyRegistry)},
}
channel, err := ac.RealtimeClient(RealtimeOptions{
DocTypes: []string{"io.cozy.jobs", "io.cozy.jobs.logs"},
})
if err != nil {
return err
}
defer func() {
if opts.Logs != nil {
close(opts.Logs)
}
channel.Close()
}()
res, err := ac.Req(&request.Options{
Method: "POST",
Path: "/instances/updates",
Queries: q,
})
if err != nil {
return err
}
defer res.Body.Close()
var job job.Job
if err = json.NewDecoder(res.Body).Decode(&job); err != nil {
return err
}
for evt := range channel.Channel() {
if evt.Event == "error" {
return fmt.Errorf("realtime: %s", evt.Payload.Title)
}
if evt.Payload.ID != job.ID() {
continue
}
switch evt.Payload.Type {
case "io.cozy.jobs":
if err = json.Unmarshal(evt.Payload.Doc, &job); err != nil {
return err
}
if job.State == "errored" {
return fmt.Errorf("error executing updates: %s", job.Error)
}
if job.State == "done" {
return nil
}
case "io.cozy.jobs.logs":
if opts.Logs != nil {
var log JobLog
if err = json.Unmarshal(evt.Payload.Doc, &log); err != nil {
return err
}
opts.Logs <- &log
}
}
}
return err
}

// Export launch the creation of a tarball to export data from an instance.
func (ac *AdminClient) Export(opts *ExportOptions) error {
if !validDomain(opts.Domain) {
Expand Down
49 changes: 0 additions & 49 deletions cmd/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ var flagTrace bool
var flagPassphrase string
var flagForce bool
var flagJSON bool
var flagForceRegistry bool
var flagOnlyRegistry bool
var flagSwiftLayout int
var flagCouchCluster int
var flagUUID string
Expand Down Expand Up @@ -871,47 +869,6 @@ var findOauthClientCmd = &cobra.Command{
},
}

var updateCmd = &cobra.Command{
Use: "update [slugs...]",
Short: "Start the updates for the specified domain instance.",
Long: `Start the updates for the specified domain instance. Use whether the --domain
flag to specify the instance or the --all-domains flags to updates all domains.
The slugs arguments can be used to select which applications should be
updated.`,
Aliases: []string{"updates"},
RunE: func(cmd *cobra.Command, args []string) error {
ac := newAdminClient()
if flagAllDomains {
logs := make(chan *client.JobLog)
go func() {
for log := range logs {
fmt.Fprintf(os.Stdout, "[%s][time:%s]", log.Level, log.Time.Format(time.RFC3339))
for k, v := range log.Data {
fmt.Fprintf(os.Stdout, "[%s:%s]", k, v)
}
fmt.Fprintf(os.Stdout, " %s\n", log.Message)
}
}()
return ac.Updates(&client.UpdatesOptions{
Slugs: args,
ForceRegistry: flagForceRegistry,
OnlyRegistry: flagOnlyRegistry,
Logs: logs,
})
}
if flagDomain == "" {
return errMissingDomain
}
return ac.Updates(&client.UpdatesOptions{
Domain: flagDomain,
DomainsWithContext: flagContextName,
Slugs: args,
ForceRegistry: flagForceRegistry,
OnlyRegistry: flagOnlyRegistry,
})
},
}

var exportCmd = &cobra.Command{
Use: "export",
Short: "Export an instance",
Expand Down Expand Up @@ -1105,7 +1062,6 @@ func init() {
instanceCmdGroup.AddCommand(oauthRefreshTokenInstanceCmd)
instanceCmdGroup.AddCommand(oauthClientInstanceCmd)
instanceCmdGroup.AddCommand(findOauthClientCmd)
instanceCmdGroup.AddCommand(updateCmd)
instanceCmdGroup.AddCommand(exportCmd)
instanceCmdGroup.AddCommand(importCmd)
instanceCmdGroup.AddCommand(showSwiftPrefixInstanceCmd)
Expand Down Expand Up @@ -1168,11 +1124,6 @@ func init() {
lsInstanceCmd.Flags().BoolVar(&flagJSON, "json", false, "Show each line as a json representation of the instance")
lsInstanceCmd.Flags().StringSliceVar(&flagListFields, "fields", nil, "Arguments shown for each line in the list")
lsInstanceCmd.Flags().BoolVar(&flagAvailableFields, "available-fields", false, "List available fields for --fields option")
updateCmd.Flags().BoolVar(&flagAllDomains, "all-domains", false, "Work on all domains iteratively")
updateCmd.Flags().StringVar(&flagDomain, "domain", "", "Specify the domain name of the instance")
updateCmd.Flags().StringVar(&flagContextName, "context-name", "", "Work only on the instances with the given context name")
updateCmd.Flags().BoolVar(&flagForceRegistry, "force-registry", false, "Force to update all applications sources from git to the registry")
updateCmd.Flags().BoolVar(&flagOnlyRegistry, "only-registry", false, "Only update applications installed from the registry")
exportCmd.Flags().StringVar(&flagDomain, "domain", "", "Specify the domain name of the instance")
exportCmd.Flags().StringVar(&flagPath, "path", "", "Specify the local path where to store the export archive")
importCmd.Flags().StringVar(&flagDomain, "domain", "", "Specify the domain name of the instance")
Expand Down
1 change: 0 additions & 1 deletion cozy.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ jobs:
# - "trash-files": async deletion of files in the trash
# - "clean-old-trashed": deletion of old files and directories after some time
# - "unzip": unzipping tarball
# - "updates": run updates for installed applications (deprecated)
# - "zip": creating a zip tarball
#
# When no configuration is given for a worker, a default configuration is
Expand Down
1 change: 0 additions & 1 deletion docs/cli/cozy-stack_instances.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ cozy-stack instances <command> [flags]
* [cozy-stack instances token-cli](cozy-stack_instances_token-cli.md) - Generate a new CLI access token (global access)
* [cozy-stack instances token-konnector](cozy-stack_instances_token-konnector.md) - Generate a new konnector token
* [cozy-stack instances token-oauth](cozy-stack_instances_token-oauth.md) - Generate a new OAuth access token
* [cozy-stack instances update](cozy-stack_instances_update.md) - Start the updates for the specified domain instance.

40 changes: 0 additions & 40 deletions docs/cli/cozy-stack_instances_update.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,3 @@ It can be launched from command-line with:
```sh
$ cozy-stack jobs run migrations --domain example.mycozy.cloud --json '{"type": "to-swift-v3"}'
```

## Deprecated workers

### updates

The `updates` worker was used for updating applications when there were no
auto-update mechanism.
2 changes: 1 addition & 1 deletion pkg/config/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestConfigUnmarshal(t *testing.T) {
assert.Equal(t, true, cfg.Jobs.AllowList)
assert.EqualValues(t, []Worker{
{
WorkerType: "updates",
WorkerType: "zip",
Concurrency: &one,
MaxExecCount: &one,
Timeout: &oneHour,
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config/testdata/full_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
defaultDurationToKeep: 1H
imagemagick_convert_cmd: some-cmd
workers:
updates:
zip:
concurrency: 1
max_exec_count: 1
timeout: 1h
Expand Down
51 changes: 0 additions & 51 deletions scripts/completion/cozy-stack.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3274,52 +3274,6 @@ _cozy-stack_instances_token-oauth()
noun_aliases=()
}

_cozy-stack_instances_update()
{
last_command="cozy-stack_instances_update"

command_aliases=()

commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--all-domains")
local_nonpersistent_flags+=("--all-domains")
flags+=("--context-name=")
two_word_flags+=("--context-name")
local_nonpersistent_flags+=("--context-name")
local_nonpersistent_flags+=("--context-name=")
flags+=("--domain=")
two_word_flags+=("--domain")
local_nonpersistent_flags+=("--domain")
local_nonpersistent_flags+=("--domain=")
flags+=("--force-registry")
local_nonpersistent_flags+=("--force-registry")
flags+=("--only-registry")
local_nonpersistent_flags+=("--only-registry")
flags+=("--admin-host=")
two_word_flags+=("--admin-host")
flags+=("--admin-port=")
two_word_flags+=("--admin-port")
flags+=("--config=")
two_word_flags+=("--config")
two_word_flags+=("-c")
flags+=("--host=")
two_word_flags+=("--host")
flags+=("--port=")
two_word_flags+=("--port")
two_word_flags+=("-p")

must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}

_cozy-stack_instances()
{
last_command="cozy-stack_instances"
Expand Down Expand Up @@ -3367,11 +3321,6 @@ _cozy-stack_instances()
commands+=("token-cli")
commands+=("token-konnector")
commands+=("token-oauth")
commands+=("update")
if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
command_aliases+=("updates")
aliashash["updates"]="update"
fi

flags=()
two_word_flags=()
Expand Down
32 changes: 0 additions & 32 deletions web/instances/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/cozy/cozy-stack/model/app"
"github.com/cozy/cozy-stack/model/instance"
"github.com/cozy/cozy-stack/model/instance/lifecycle"
"github.com/cozy/cozy-stack/model/job"
"github.com/cozy/cozy-stack/model/oauth"
"github.com/cozy/cozy-stack/model/session"
"github.com/cozy/cozy-stack/model/sharing"
Expand All @@ -22,7 +21,6 @@ import (
"github.com/cozy/cozy-stack/pkg/jsonapi"
"github.com/cozy/cozy-stack/pkg/prefixer"
"github.com/cozy/cozy-stack/pkg/utils"
"github.com/cozy/cozy-stack/worker/updates"
"github.com/labstack/echo/v4"
)

Expand Down Expand Up @@ -282,35 +280,6 @@ func deleteHandler(c echo.Context) error {
return c.NoContent(http.StatusNoContent)
}

func updatesHandler(c echo.Context) error {
slugs := utils.SplitTrimString(c.QueryParam("Slugs"), ",")
domain := c.QueryParam("Domain")
domainsWithContext := c.QueryParam("DomainsWithContext")
forceRegistry, _ := strconv.ParseBool(c.QueryParam("ForceRegistry"))
onlyRegistry, _ := strconv.ParseBool(c.QueryParam("OnlyRegistry"))
msg, err := job.NewMessage(&updates.Options{
Slugs: slugs,
Force: true,
ForceRegistry: forceRegistry,
OnlyRegistry: onlyRegistry,
Domain: domain,
DomainsWithContext: domainsWithContext,
AllDomains: domain == "",
})
if err != nil {
return err
}
j, err := job.System().PushJob(prefixer.GlobalPrefixer, &job.JobRequest{
WorkerType: "updates",
Message: msg,
ForwardLogs: true,
})
if err != nil {
return wrapError(err)
}
return c.JSON(http.StatusOK, j)
}

func setAuthMode(c echo.Context) error {
domain := c.Param("domain")
inst, err := lifecycle.GetInstance(domain)
Expand Down Expand Up @@ -684,7 +653,6 @@ func Routes(router *echo.Group) {
router.DELETE("/:domain/sessions", cleanSessions)

// Advanced features for instances
router.POST("/updates", updatesHandler)
router.GET("/:domain/last-activity", lastActivity)
router.POST("/:domain/export", exporter)
router.GET("/:domain/exports/:export-id/data", dataExporter)
Expand Down
1 change: 0 additions & 1 deletion web/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
_ "github.com/cozy/cozy-stack/worker/sms"
_ "github.com/cozy/cozy-stack/worker/thumbnail"
_ "github.com/cozy/cozy-stack/worker/trash"
_ "github.com/cozy/cozy-stack/worker/updates"
)

type (
Expand Down
Loading

0 comments on commit 3004306

Please sign in to comment.