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

Docs for ActivityWorker #25

Open
sclasen opened this issue Apr 11, 2015 · 7 comments
Open

Docs for ActivityWorker #25

sclasen opened this issue Apr 11, 2015 · 7 comments

Comments

@sclasen
Copy link
Owner

sclasen commented Apr 11, 2015

once #24 is in

@ryanwalls
Copy link
Contributor

+1. Specifically, the coordinated handlers could use some documentation. Not really clear what start, tick, and cancel functions should be responsible for and what state they should maintain (if any.)

@sclasen
Copy link
Owner Author

sclasen commented Feb 3, 2016

not really docs, but the tests have 3 examples of coordinated handlers here

https://github.com/sclasen/swfsm/blob/master/activity/coordinated_worker_test.go#L177-L254

the tick counting example maintains state, which is used in the test here

https://github.com/sclasen/swfsm/blob/master/activity/coordinated_worker_test.go#L172

@ryanwalls
Copy link
Contributor

Yeah, I had looked through those. Tick is the main point of confusion. Seems to be called every heartbeat? Is it supposed to do work? (In one test the tick function was called "Work"). Start = used to start work. Cancel = used to cancel work. Tick= ?

@sclasen
Copy link
Owner Author

sclasen commented Feb 4, 2016

@ryanwalls yeah, so lets take the example of running some sort of long running job.

Start would start the job running.

Tick would monitor the job, perhaps returning updates if desired. It does have a return type that is a bit strange.

  • Tick that returns false, nil, nil just expresses that the job is still running.
  • Tick that returns false, &SomeStruct{}, nil will express that the job is still running and also send an 'ActivityUpdated' signal back to the FSM with SomeStruct{} as the Input.
  • Tick that returns true, &SomeStruct{}, nil, expresses that the job/activity is done and send SomeStruct{} back as the result. as well as stops heartbeating.
  • Tick that returns true, nil, nil, expresses that the job is done and send no result back, as well as stops heartbeating.
  • Tick that returns false, nil, err expresses that the job/activity failed and sends back err as the reason. as well as stops heartbeating.

If the heartbeating goroutine recieves Canceled: true in its heartbeat response, it stops heartbeating and calls Cancel.

@sclasen
Copy link
Owner Author

sclasen commented Feb 4, 2016

Of course you could do slightly different things with Start and Tick too. Start could verify that you could connect to a queue or some such, and Tick could poll the queue and consume it.

@ryanwalls
Copy link
Contributor

@sclasen Awesome. That was exactly what I needed. Makes sense.

ryanwalls pushed a commit to ryanwalls/swfsm that referenced this issue Jul 1, 2016
@ryanwalls
Copy link
Contributor

@sclasen I'm 99% sure that true/false should be switched in your comment above. #25 (comment)

When tick returns false the coordinate method returns. Here's the relevant piece of code:

    cont, res, err := c.handler.Tick(activityTask, input)
            if !cont {
                return res, err
            }

Updating my PR in just a minute to reflect the corrected description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants