Code Monkey home page Code Monkey logo

Comments (6)

SerafimArts avatar SerafimArts commented on June 14, 2024

Hello! We deliberately avoided the possibility of injecting any variables inside the Workflow, since changing these values can change the behavior of this Workflow, which will break absolutely the entire code.

For example:

#[WorkflowInterface]
class GreetingWorkflow
{
    public function __construct(private Some $service) {}
    
    public function greet(string $name): \Generator
    {
        if ($this->service->doSomething()) {
            yield $this->greetingActivity->composeGreeting('Hello', $name);
        }
        
        return yield $this->greetingActivity->composeGreeting('world', $name);
    }
}

In this case, the argument is a reference to an external service dependency that may have side effects that will break the workflow execution.

Moreover, when implementing the SDK, we focused on Java SDK, where there are no arguments for the workflow constructor.

However, the example with your code looks quite convincing. So we need to think about how to solve your problem.

from sdk-php.

tsurdilo avatar tsurdilo commented on June 14, 2024

@Zylius
as @SerafimArts mentioned, workflows must be deterministic, and you register the workflow type with the worker, not an instance.

You can achieve what you are looking for, I believe, with WorkflowClientInterface->startWithSignal (when you are starting your workflow execution, and not when you are registering your workflow with worker)

startWithSignal will start workflow execution (if no active ones is available) and send the signal on start. The data that you want to "inject" can be the signal data.

from sdk-php.

Zylius avatar Zylius commented on June 14, 2024

Hey, thanks guys! I wasn't aware of startWithSignal and Signal functionality. I'll try it out!

See what we're trying to do here, is generate temporal workflows (just like my past question about activities #110) from our legacy configuration. Now the example you gave @SerafimArts, kinda got me a little worried. What I've been trying to avoid is generating "stub" php classes for workflows from our YAML files. But if that's what we have to do, I'll be willing to do it.

Update concerning startWithSignal: lets say we have two services. ServiceA starts the workflow, and has its interface. ServiceB implements the workflow interface. ServiceA shouldn't be the one injecting configuration into ServiceB workflow, since ServiceB is the one responsible for it. So I don't think this will work in our case :/

from sdk-php.

wolfy-j avatar wolfy-j commented on June 14, 2024

FYI, with local activities, you will be able to "upload" the workflow config via calling the activity. It will be deterministic since it will freeze the workflow state in history.

Local Activities are planned in the 1.1 version of this SDK. In the meantime use classic activities.

This way workflow fully controls its config (i assume declarative DSL) and does not expose anything to the outside. This should solve your case without exposing anything.

@tsurdilo I believe the community can greatly benefit from a simple example of how to convert legacy DSL workflows into temporal workflows.

from sdk-php.

wolfy-j avatar wolfy-j commented on June 14, 2024

Something like that:

public function workflowMethod(string $type) 
{
     $yaml = yield $this->config->loadParsedConfig($type);

     // do something with yaml, the workflow is not detached from your config file and even if you changes it - it will remain deterministic
}

So, in simple words, do the data DI via deterministic markers:

  1. Local Activity
  2. Activity
  3. Signal
  4. Also you can use side-effect if the file located withing the current filesystem, but be careful as it's blocking call

from sdk-php.

Zylius avatar Zylius commented on June 14, 2024

Thank you very much! We've already done this and it works great. Kinda asked the question without fully understanding how temporal flow works. 🙇

from sdk-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.