temporal 官网示例
python:
@workflow.defn
class SleepForDaysWorkflow:
# Send an email every 30 days, for the year
@workflow.run
async def run(self) -> None:
for i in range(12):
# Activities have built-in support for timeouts and retries!
await workflow.execute_activity(
send_email,
start_to_close_timeout=timedelta(seconds=10),
)
# Sleep for 30 days (yes, really)!
await workflow.sleep(timedelta(days=30))
ruby:
# Send an email every 30 days, for the year
class SleepForDaysWorkflow < Temporalio::Workflow::Definition
def execute
12.times do
# Activities have built-in support for timeouts and retries!
Temporalio::Workflow.execute_activity(
SendEmailActivity,
start_to_close_timeout: 10
)
# Sleep for 30 days (yes, really)!
Temporalio::Workflow.sleep(30 * 24 * 60 * 60)
end
end
end
C#:
[Workflow]
public class SleepForDaysWorkflow
{
// Send an email every 30 days, for the year
[WorkflowRun]
public async Task RunAsync()
{
for (int i = 0; i < 12; i++)
{
// Activities have built-in support for timeouts and retries!
await Workflow.ExecuteActivityAsync(
(Activities act) => act.SendEmail(),
new() { StartToCloseTimeout = TimeSpan.FromSeconds(10) });
// Sleep for 30 days (yes, really)!
await Workflow.DelayAsync(TimeSpan.FromDays(30));
}
}
}
PHP:
class SleepForDaysWorkflow implements SleepForDaysWorkflowInterface
{
// Send an email every 30 days.
public function sleepForDays(): void
{
for ($i = 0; $i < 12; $i++) {
// Activities have timeouts, and will be retried by default!
$this->sendEmailActivity->sendEmail();
// Sleep for 30 days (yes, really)!
Workflow::sleep(30 * 24 * 60 * 60)
}
}
}
感觉对于 java 程序员 php 的心智负担好小啊
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.