dateutility. This program returns a string representing the system's current time, e.g.:
Tue Jun 8 14:53:51 UTC 2021.
Taskobjects to be computed
Goleminstance and using it to execute our tasks
vm, we're getting a payload definition for our providers. The only input we must provide at this point is the image hash. In the case of this example we're using a pre-uploaded, minimal image based on Alpine Linux.
tasksarray contains a single item of type
Taskwhich has no data associated with it. This means we only need a single item to be computed and that the worker function does not need any additional parameters.
Taskobject refers to a single piece of computation within your app and typically holds some data. For example, in a program which operates on a huge file, a single
Taskcould be holding one chunk of that file to be processed by one of many providers involved.
main()function we create an instance of
Executorin the case of JS API) and use it to request our tasks.
Golem/Executoris the heart of Golem's API - it handles communication with the local Golem node, processes payments for completed tasks and, most importantly, provides an easy way of requesting resources in the Golem network.
budgetspecifies our desired budget (in GLM) for the total cost of all tasks computed using this
subnet_tagspecifies the name of a Golem network sub-network we'd like to use for all Golem communication performed by this
Golem/Executorinstance initialized we can now request some tasks!
workeris the function which defines the steps that should happen for each provider node in order to process a
tasksis the array of
Taskobjects we have created
payloadis the payload definition for providers which we created using the function
execute_tasks/submitreturns an asynchronous iterator of
Taskobjects, hence the
async for/for awaitstatement. Items returned by this iterator are successfully completed tasks in the order they were computed.
workerfunction is what defines the interaction between our requestor node and each provider computing one or more of our tasks. It's called once per provider node with which our requestor has struck an agreement.
WorkContextgives us a simple interface to construct a script that translates directly to commands interacting with the execution unit on provider's end. Using this object we can schedule commands such as transferring files, running programs etc.
Taskobjects yields task fragments assigned to this provider. In a more complex scenario each
Taskobject would be carrying its own piece of data to be used during computation.
context.run. This means that, once committed, the provider's exe unit will receive an instruction to make a call to
/bin/sh -c date.
future_resultsafter the script has been yielded, we ensure the results are available and unwrap them from the awaitable object.
task.accept_resultto mark the task as successfully finished and pass it the result object. This will cause our task to be passed to the queue of completed tasks which gets processed in our
yagnanode running and set up as a requestor (take a look here in case of any doubts: Requestor development: a quick primer). You can then issue the following command:
hello.pyfile. You'll also need to provide your node's actual app key. If everything went fine you should see a log similar to the one below:
Tue Jun 15 12:51:24 UTC 2021is the result we received from executing the
datecommand inside our provider's exe unit.