forked from temporalio/samples-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activities.go
36 lines (27 loc) · 835 Bytes
/
activities.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package pso
import (
"context"
"go.temporal.io/sdk/activity"
)
/**
* Sample activities used by file processing sample workflow.
*/
const (
InitParticleActivityName = "initParticleActivityName"
UpdateParticleActivityName = "updateParticleActivityName"
)
func InitParticleActivity(ctx context.Context, swarm Swarm) (Particle, error) {
logger := activity.GetLogger(ctx)
logger.Info("initParticleActivity started.")
particle := NewParticle(&swarm)
particle.UpdateFitness(&swarm)
return *particle, nil
}
func UpdateParticleActivity(ctx context.Context, swarm Swarm, particleIdx int) (Particle, error) {
logger := activity.GetLogger(ctx)
logger.Info("updateParticleActivity started.")
particle := swarm.Particles[particleIdx]
particle.UpdateLocation(&swarm)
particle.UpdateFitness(&swarm)
return *particle, nil
}