-
Notifications
You must be signed in to change notification settings - Fork 89
/
create_schedule_spec.rb
87 lines (77 loc) · 3.29 KB
/
create_schedule_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require "temporal/errors"
require "temporal/schedule/backfill"
require "temporal/schedule/calendar"
require "temporal/schedule/interval"
require "temporal/schedule/schedule"
require "temporal/schedule/schedule_spec"
require "temporal/schedule/schedule_policies"
require "temporal/schedule/schedule_state"
require "temporal/schedule/start_workflow_action"
describe "Temporal.create_schedule", :integration do
let(:example_schedule) do
workflow_id = SecureRandom.uuid
Temporal::Schedule::Schedule.new(
spec: Temporal::Schedule::ScheduleSpec.new(
calendars: [Temporal::Schedule::Calendar.new(day_of_week: "*", hour: "18", minute: "30")],
intervals: [Temporal::Schedule::Interval.new(every: 6000, offset: 300)],
cron_expressions: ["@hourly"],
jitter: 30,
# Set an end time so that the test schedule doesn't run forever
end_time: Time.now + 600
),
action: Temporal::Schedule::StartWorkflowAction.new(
"HelloWorldWorkflow",
"Test",
options: {
workflow_id: workflow_id,
task_queue: integration_spec_task_queue
}
),
policies: Temporal::Schedule::SchedulePolicies.new(
overlap_policy: :buffer_one
),
state: Temporal::Schedule::ScheduleState.new(
notes: "Created by integration test"
)
)
end
it "can create schedules" do
namespace = integration_spec_namespace
schedule_id = SecureRandom.uuid
create_response = Temporal.create_schedule(
namespace,
schedule_id,
example_schedule,
memo: {"schedule_memo" => "schedule memo value"},
trigger_immediately: true,
backfill: Temporal::Schedule::Backfill.new(start_time: (Date.today - 90).to_time, end_time: Time.now)
)
expect(create_response).to(be_an_instance_of(Temporalio::Api::WorkflowService::V1::CreateScheduleResponse))
describe_response = Temporal.describe_schedule(namespace, schedule_id)
expect(describe_response.memo).to(eq({"schedule_memo" => "schedule memo value"}))
expect(describe_response.schedule.spec.jitter.seconds).to(eq(30))
expect(describe_response.schedule.policies.overlap_policy).to(eq(:SCHEDULE_OVERLAP_POLICY_BUFFER_ONE))
expect(describe_response.schedule.action.start_workflow.workflow_type.name).to(eq("HelloWorldWorkflow"))
expect(describe_response.schedule.state.notes).to(eq("Created by integration test"))
end
it "can create schedules with a minimal set of fields" do
namespace = integration_spec_namespace
schedule_id = SecureRandom.uuid
schedule = Temporal::Schedule::Schedule.new(
spec: Temporal::Schedule::ScheduleSpec.new(
cron_expressions: ["@hourly"],
# Set an end time so that the test schedule doesn't run forever
end_time: Time.now + 600
),
action: Temporal::Schedule::StartWorkflowAction.new(
"HelloWorldWorkflow",
"Test",
options: {task_queue: integration_spec_task_queue}
)
)
Temporal.create_schedule(namespace, schedule_id, schedule)
describe_response = Temporal.describe_schedule(namespace, schedule_id)
expect(describe_response.schedule.action.start_workflow.workflow_type.name).to(eq("HelloWorldWorkflow"))
expect(describe_response.schedule.policies.overlap_policy).to(eq(:SCHEDULE_OVERLAP_POLICY_SKIP))
end
end