Adding or removing activities after the Workflow is started #98
Replies: 3 comments 2 replies
-
If all you do is add something to the workflow at the end, you should be okay. You just stop the queue workers, deploy the new code and restart the workers with the new code. If you make changes that would replace or remove activities then that would probably break the workflow. An upcoming feature will be to add
Here's a quick breakdown of the parameters:
The function would return an integer representing the current version number for the given change. It would allow Laravel Workflow to keep track of different stages of changes and manage them accordingly. Here's a hypothetical example: public function execute()
{
$result1 = yield ActivityStub::make(ActivityA::class);
$result2 = yield ActivityStub::make(ActivityB::class);
return $result2;
} Say we have a workflow that uses ActivityA. Now we need to replace ActivityA with ActivityC in an update. This change can be challenging if a workflow has already started, right? But with our proposed method, the system could be smart enough to understand the change and adapt accordingly. public function execute()
{
$v = yield WorkflowStub::getVersion('Step1', WorkflowStub::DEFAULT_VERSION, 1);
if ($v === WorkflowStub::DEFAULT_VERSION) {
$result1 = yield ActivityStub::make(ActivityA::class);
} else {
$result1 = yield ActivityStub::make(ActivityC::class);
}
$result2 = yield ActivityStub::make(ActivityB::class);
return $result2;
} A workflow that has already started and completed ActivityA would return Would this accomplish what you're asking? |
Beta Was this translation helpful? Give feedback.
-
@im-Clement Ah I see what you mean now. I think if you keep the list of activities in an array you could add to the array using a signal. class MyWorkflow extends Workflow
{
protected $activities = [];
#[SignalMethod]
public function addActivity($activity)
{
$this->activities[] = $activity;
}
public function execute()
{
$this->activities = [
MyActivityA::class,
MyActivityB::class,
];
foreach ($this->activities as $activity) {
yield ActivityStub::make($activity);
}
}
} While the workflow is running you can signal it like this to add a new activity. $workflow = WorkflowStub::load($id);
$workflow->addActivity(MyActivityC::class); |
Beta Was this translation helpful? Give feedback.
-
Any updates on this feature? |
Beta Was this translation helpful? Give feedback.
-
Hello,
Thank you for the great package.
Is there a way to add new activities (or remove some of the existing ones) after the workflow is started?
Beta Was this translation helpful? Give feedback.
All reactions