refactor: simplify weather art creation process
- Moved weather art creation inside the transaction block - Updated variable names for clarity - Ensured the transaction block manages the creation and attachment of images more clearly This refactor improves the readability and maintainability of the `create_weather_art` method while preserving its original functionality. The changes also ensure that the transaction affects the creation and attachment operations coherently.
This commit is contained in:
parent
c489c19467
commit
c27bab7dc9
@ -40,8 +40,8 @@ class GenerateWeatherArtWorker
|
|||||||
def create_weather_art(weather_data, prompt, image_url)
|
def create_weather_art(weather_data, prompt, image_url)
|
||||||
tempfile = nil
|
tempfile = nil
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
weather_art = ActiveRecord::Base.transaction do
|
||||||
weather_art = city.weather_arts.create!(
|
w = city.weather_arts.create!(
|
||||||
weather_date: Date.today,
|
weather_date: Date.today,
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
**weather_data
|
**weather_data
|
||||||
@ -49,12 +49,12 @@ class GenerateWeatherArtWorker
|
|||||||
|
|
||||||
tempfile = Down.download(image_url)
|
tempfile = Down.download(image_url)
|
||||||
|
|
||||||
weather_art.image.attach(
|
w.image.attach(
|
||||||
io: File.open(tempfile.path),
|
io: File.open(tempfile.path),
|
||||||
filename: generate_filename,
|
filename: generate_filename,
|
||||||
content_type: "image/png"
|
content_type: "image/png"
|
||||||
)
|
)
|
||||||
weather_art
|
w
|
||||||
end
|
end
|
||||||
weather_art.webp_image.processed
|
weather_art.webp_image.processed
|
||||||
weather_art.preview_image.processed
|
weather_art.preview_image.processed
|
||||||
|
Loading…
Reference in New Issue
Block a user