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

fix(api): lint #2899

Merged
merged 4 commits into from
Jun 18, 2018
Merged
Changes from 1 commit
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
Next Next commit
fix(api): lint
fsamin committed Jun 15, 2018
commit 0215d06eaefc88bb38945a793985bb736df0d135
5 changes: 1 addition & 4 deletions engine/api/api.go
Original file line number Diff line number Diff line change
@@ -516,9 +516,6 @@ func (a *API) Serve(ctx context.Context) error {
}
a.InitRouter()

//Init events package
event.Cache = a.Cache

//Initiliaze hook package
hook.Init(a.Config.URL.API)

@@ -566,7 +563,7 @@ func (a *API) Serve(ctx context.Context) error {
Topic: a.Config.Events.Kafka.Topic,
MaxMessageByte: a.Config.Events.Kafka.MaxMessageBytes,
}
if err := event.Initialize(kafkaOptions); err != nil {
if err := event.Initialize(kafkaOptions, a.Cache); err != nil {
log.Error("error while initializing event system: %s", err)
} else {
go event.DequeueEvent(ctx)
10 changes: 5 additions & 5 deletions engine/api/event/event.go
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@ import (
"os"
"strings"

"github.com/ovh/cds/sdk/namesgenerator"

"github.com/ovh/cds/engine/api/cache"
"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/log"
"github.com/ovh/cds/sdk/namesgenerator"
)

var hostname, cdsname string
@@ -35,9 +35,9 @@ func getBroker(t string, option interface{}) (Broker, error) {
}

// Initialize initializes event system
func Initialize(k KafkaConfig) error {
func Initialize(k KafkaConfig, cache cache.Store) error {
subscribers = make([]chan<- sdk.Event, 0)

store = cache
var err error
hostname, err = os.Hostname()
if err != nil {
@@ -74,7 +74,7 @@ func Subscribe(ch chan<- sdk.Event) {
func DequeueEvent(c context.Context) {
for {
e := sdk.Event{}
Cache.DequeueWithContext(c, "events", &e)
store.DequeueWithContext(c, "events", &e)
if err := c.Err(); err != nil {
log.Error("Exiting event.DequeueEvent : %v", err)
return
8 changes: 4 additions & 4 deletions engine/api/event/publish.go
Original file line number Diff line number Diff line change
@@ -14,10 +14,10 @@ import (
"github.com/ovh/cds/sdk/log"
)

var Cache cache.Store
var store cache.Store

func publishEvent(e sdk.Event) {
Cache.Enqueue("events", e)
store.Enqueue("events", e)

// send to cache for cds repositories manager
var toSkipSendReposManager bool
@@ -29,15 +29,15 @@ func publishEvent(e sdk.Event) {
}
}
if !toSkipSendReposManager {
Cache.Enqueue("events_repositoriesmanager", e)
store.Enqueue("events_repositoriesmanager", e)
}

b, err := json.Marshal(e)
if err != nil {
log.Warning("publishEvent> Cannot marshal event %+v", e)
return
}
Cache.Publish("events_pubsub", string(b))
store.Publish("events_pubsub", string(b))
}

// Publish sends a event to a queue
2 changes: 1 addition & 1 deletion engine/api/event/publish_environment.go
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ func publishEnvironmentEvent(payload interface{}, key, envName string, u *sdk.Us
// PublishEnvironmentAdd publishes an event for the creation of the given environment
func PublishEnvironmentAdd(projKey string, env sdk.Environment, u *sdk.User) {
e := sdk.EventEnvironmentAdd{
env,
Environment: env,
}
publishEnvironmentEvent(e, projKey, env.Name, u)
}
2 changes: 1 addition & 1 deletion engine/api/event/publish_pipeline.go
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ func PublishPipelineDelete(key string, pip sdk.Pipeline, u *sdk.User) {
// PublishPipelinePermissionAdd publishes an event for pipeline permission adding
func PublishPipelinePermissionAdd(key string, pipName string, gp sdk.GroupPermission, u *sdk.User) {
e := sdk.EventPipelinePermissionAdd{
gp,
Permission: gp,
}
publishPipelineEvent(e, key, pipName, u)
}
2 changes: 1 addition & 1 deletion engine/api/event/publish_workflow.go
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ func publishWorkflowEvent(payload interface{}, key, workflowName string, u *sdk.
publishEvent(event)
}

// PublishAddWorkflow publishes an event for the creation of the given Workflow
// PublishWorkflowAdd publishes an event for the creation of the given Workflow
func PublishWorkflowAdd(projKey string, w sdk.Workflow, u *sdk.User) {
e := sdk.EventWorkflowAdd{
Workflow: w,
7 changes: 3 additions & 4 deletions engine/api/event/publish_workflow_run.go
Original file line number Diff line number Diff line change
@@ -11,8 +11,7 @@ import (
"github.com/ovh/cds/sdk"
)

// PublishRunWorkflow
func PublishRunWorkflow(payload interface{}, key, workflowName, appName, pipName, envName string, num int64, u *sdk.User) {
func publishRunWorkflow(payload interface{}, key, workflowName, appName, pipName, envName string, num int64, u *sdk.User) {
event := sdk.Event{
Timestamp: time.Now(),
Hostname: hostname,
@@ -44,7 +43,7 @@ func PublishWorkflowRun(wr sdk.WorkflowRun, projectKey string) {
LastModified: wr.LastModified.Unix(),
Tags: wr.Tags,
}
PublishRunWorkflow(e, projectKey, wr.Workflow.Name, "", "", "", wr.Number, nil)
publishRunWorkflow(e, projectKey, wr.Workflow.Name, "", "", "", wr.Number, nil)
}

// PublishWorkflowNodeRun publish event on a workflow node run
@@ -99,5 +98,5 @@ func PublishWorkflowNodeRun(db gorp.SqlExecutor, nr sdk.WorkflowNodeRun, w sdk.W
if sdk.StatusIsTerminated(nr.Status) {
e.Done = nr.Done.Unix()
}
PublishRunWorkflow(e, w.ProjectKey, w.Name, appName, pipName, envName, nr.Number, nil)
publishRunWorkflow(e, w.ProjectKey, w.Name, appName, pipName, envName, nr.Number, nil)
}