-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathworker_specific_activities.rb
More file actions
52 lines (41 loc) · 1.25 KB
/
worker_specific_activities.rb
File metadata and controls
52 lines (41 loc) · 1.25 KB
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
# frozen_string_literal: true
require 'digest'
require 'logger'
require 'net/http'
require 'tempfile'
require 'temporalio/activity'
require 'uri'
module WorkerSpecificTaskQueues
module WorkerSpecificActivities
class DownloadFileActivity < Temporalio::Activity::Definition
def execute(url)
# Simulate slow activity
sleep(3)
file = Tempfile.create
Temporalio::Activity::Context.current.logger.info("Downloading #{url} to #{file.path}")
file.write(Net::HTTP.get(URI(url)))
file.close
file.path
end
end
class WorkOnFileActivity < Temporalio::Activity::Definition
def execute(file_path)
# Simulate slow activity
sleep(3)
# Calculate checksum to simulate work
checksum = Digest::SHA256.file(file_path).hexdigest
Temporalio::Activity::Context.current.logger.info("Did some work on #{file_path}, checksum: #{checksum}")
nil
end
end
class CleanupFileActivity < Temporalio::Activity::Definition
def execute(file_path)
# Simulate slow activity
sleep(3)
Temporalio::Activity::Context.current.logger.info("Removing #{file_path}")
File.unlink(file_path)
nil
end
end
end
end