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

maybe more clear with a new issue id,about why ao.send keep silence under Cron mode of spawned sub-process #228

Open
xgocn opened this issue Sep 18, 2024 · 10 comments

Comments

@xgocn
Copy link
Contributor

xgocn commented Sep 18, 2024

    -- parent process : l7ph6gka-mmrVE5P23lRa-1BWgQC8MXH8FcTbs6wk_U 
    Handlers.add(
    'ping',
    Handlers.utils.hasMatchingTag('Action', 'Ping'),
    function(msg)
        print("Received Ping from: " .. msg.From)
        msg.reply({ Data = 'Pong from Main Process:' .. tostring(ao.id)})
    end
   )

    local newProcess = ao.spawn(ao.env.Module.Id, {
        Authority = ao.id,
        ["Cron-Tag-Action"] = "Cron",
        ["Cron-Interval"] = "10-seconds"
    }).receive()

    print(newProcess.Process)
   -- got jSj0KUIDJN8gx8PW5-MLZ_gTAaY6_EQd0N3Kl6AT6YY

    ao.send({
      Target = newProcess.Process,
      Action = 'Eval',
      Data = [[      
            Handlers.add(
                'CronTick', 
                Handlers.utils.hasMatchingTag('Action', 'Cron'), 
                function(msg)
                    ao.send({Target ='l7ph6gka-mmrVE5P23lRa-1BWgQC8MXH8FcTbs6wk_U',Action = 'Ping'})
                end
            )
        ]]
    })

the ao.send in Cron action of sub-process works by explicit call but not works by implicit call, maybe a bug?

@xgocn
Copy link
Contributor Author

xgocn commented Sep 19, 2024

Hi Tom @twilson63 MY HERO,we need your help!

@twilson63
Copy link
Contributor

haha, I have some time to look at it,

@twilson63
Copy link
Contributor

IDK, if this works for you, but this is how I got a spawned process to work with cron

function createProcess()
  Spawn(ao.env.Module.Id, { Authority = ao.authorities[1],
    Tags = {
      ["Cron-Tag-Action"] = "Cron",
      ["Cron-Interval"] = "1-minute"
    }
  })
end

function setOwner(pid)
  Send({ Target = pid, Action = "Eval", Data = string.format([[
    Owner = "%s"
  ]], Owner)})
  print("Set Owner: " .. pid)
end
setOwner(createProcess().receive().Process)

Then connect with aos to the processId and run .monitor to subscribe and push messages.

aos BI7Wtyy-W3VKBPM2It2VpmI2gntER_tTRGRpVA5NJxg
aos> .monitor

@twilson63
Copy link
Contributor

Cron will run, when the process receives messages, but without a monitor, cron will not push outbox to other processes.

To monitor, as the Owner of a process you have to submit a signed dataItem to the MU requesting to init the monitoring for cron messages.

@xgocn
Copy link
Contributor Author

xgocn commented Oct 1, 2024

I'll try it,what’s more exciting is I saw you again

@xgocn
Copy link
Contributor Author

xgocn commented Oct 2, 2024

I noticed that you used the command of modifying the Owner, and I'm not sure if this can expose possible problems, so I submitted this test file so that you can quickly and accurately find out if the problem exists.
test.zip

the ao.send in Cron doesn't work for unknown reason

May you try the test.zip ?

@twilson63
Copy link
Contributor

twilson63 commented Oct 2, 2024 via email

@xgocn
Copy link
Contributor Author

xgocn commented Oct 3, 2024

The spawned process is the best solution to realize NPCs concept,if each NPC runs with a monitor console window,maybe too heavy,terrible?

@twilson63
Copy link
Contributor

twilson63 commented Oct 3, 2024 via email

@xgocn
Copy link
Contributor Author

xgocn commented Oct 5, 2024

In this situation, can I use aos --watch=[process] instead of aos> .monitor ?

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